1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | (function () {
|
14 | 'use strict';
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function isObject$2(obj) {
|
29 | return obj !== null && typeof obj === 'object' && 'constructor' in obj && obj.constructor === Object;
|
30 | }
|
31 | function extend$2(target, src) {
|
32 | if (target === void 0) {
|
33 | target = {};
|
34 | }
|
35 | if (src === void 0) {
|
36 | src = {};
|
37 | }
|
38 | Object.keys(src).forEach(key => {
|
39 | if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject$2(src[key]) && isObject$2(target[key]) && Object.keys(src[key]).length > 0) {
|
40 | extend$2(target[key], src[key]);
|
41 | }
|
42 | });
|
43 | }
|
44 | const ssrDocument = {
|
45 | body: {},
|
46 | addEventListener() {},
|
47 | removeEventListener() {},
|
48 | activeElement: {
|
49 | blur() {},
|
50 | nodeName: ''
|
51 | },
|
52 | querySelector() {
|
53 | return null;
|
54 | },
|
55 | querySelectorAll() {
|
56 | return [];
|
57 | },
|
58 | getElementById() {
|
59 | return null;
|
60 | },
|
61 | createEvent() {
|
62 | return {
|
63 | initEvent() {}
|
64 | };
|
65 | },
|
66 | createElement() {
|
67 | return {
|
68 | children: [],
|
69 | childNodes: [],
|
70 | style: {},
|
71 | setAttribute() {},
|
72 | getElementsByTagName() {
|
73 | return [];
|
74 | }
|
75 | };
|
76 | },
|
77 | createElementNS() {
|
78 | return {};
|
79 | },
|
80 | importNode() {
|
81 | return null;
|
82 | },
|
83 | location: {
|
84 | hash: '',
|
85 | host: '',
|
86 | hostname: '',
|
87 | href: '',
|
88 | origin: '',
|
89 | pathname: '',
|
90 | protocol: '',
|
91 | search: ''
|
92 | }
|
93 | };
|
94 | function getDocument() {
|
95 | const doc = typeof document !== 'undefined' ? document : {};
|
96 | extend$2(doc, ssrDocument);
|
97 | return doc;
|
98 | }
|
99 | const ssrWindow = {
|
100 | document: ssrDocument,
|
101 | navigator: {
|
102 | userAgent: ''
|
103 | },
|
104 | location: {
|
105 | hash: '',
|
106 | host: '',
|
107 | hostname: '',
|
108 | href: '',
|
109 | origin: '',
|
110 | pathname: '',
|
111 | protocol: '',
|
112 | search: ''
|
113 | },
|
114 | history: {
|
115 | replaceState() {},
|
116 | pushState() {},
|
117 | go() {},
|
118 | back() {}
|
119 | },
|
120 | CustomEvent: function CustomEvent() {
|
121 | return this;
|
122 | },
|
123 | addEventListener() {},
|
124 | removeEventListener() {},
|
125 | getComputedStyle() {
|
126 | return {
|
127 | getPropertyValue() {
|
128 | return '';
|
129 | }
|
130 | };
|
131 | },
|
132 | Image() {},
|
133 | Date() {},
|
134 | screen: {},
|
135 | setTimeout() {},
|
136 | clearTimeout() {},
|
137 | matchMedia() {
|
138 | return {};
|
139 | },
|
140 | requestAnimationFrame(callback) {
|
141 | if (typeof setTimeout === 'undefined') {
|
142 | callback();
|
143 | return null;
|
144 | }
|
145 | return setTimeout(callback, 0);
|
146 | },
|
147 | cancelAnimationFrame(id) {
|
148 | if (typeof setTimeout === 'undefined') {
|
149 | return;
|
150 | }
|
151 | clearTimeout(id);
|
152 | }
|
153 | };
|
154 | function getWindow() {
|
155 | const win = typeof window !== 'undefined' ? window : {};
|
156 | extend$2(win, ssrWindow);
|
157 | return win;
|
158 | }
|
159 |
|
160 | function classesToTokens(classes) {
|
161 | if (classes === void 0) {
|
162 | classes = '';
|
163 | }
|
164 | return classes.trim().split(' ').filter(c => !!c.trim());
|
165 | }
|
166 |
|
167 | function deleteProps(obj) {
|
168 | const object = obj;
|
169 | Object.keys(object).forEach(key => {
|
170 | try {
|
171 | object[key] = null;
|
172 | } catch (e) {
|
173 |
|
174 | }
|
175 | try {
|
176 | delete object[key];
|
177 | } catch (e) {
|
178 |
|
179 | }
|
180 | });
|
181 | }
|
182 | function nextTick(callback, delay) {
|
183 | if (delay === void 0) {
|
184 | delay = 0;
|
185 | }
|
186 | return setTimeout(callback, delay);
|
187 | }
|
188 | function now() {
|
189 | return Date.now();
|
190 | }
|
191 | function getComputedStyle$1(el) {
|
192 | const window = getWindow();
|
193 | let style;
|
194 | if (window.getComputedStyle) {
|
195 | style = window.getComputedStyle(el, null);
|
196 | }
|
197 | if (!style && el.currentStyle) {
|
198 | style = el.currentStyle;
|
199 | }
|
200 | if (!style) {
|
201 | style = el.style;
|
202 | }
|
203 | return style;
|
204 | }
|
205 | function getTranslate(el, axis) {
|
206 | if (axis === void 0) {
|
207 | axis = 'x';
|
208 | }
|
209 | const window = getWindow();
|
210 | let matrix;
|
211 | let curTransform;
|
212 | let transformMatrix;
|
213 | const curStyle = getComputedStyle$1(el);
|
214 | if (window.WebKitCSSMatrix) {
|
215 | curTransform = curStyle.transform || curStyle.webkitTransform;
|
216 | if (curTransform.split(',').length > 6) {
|
217 | curTransform = curTransform.split(', ').map(a => a.replace(',', '.')).join(', ');
|
218 | }
|
219 |
|
220 |
|
221 | transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
|
222 | } else {
|
223 | transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
|
224 | matrix = transformMatrix.toString().split(',');
|
225 | }
|
226 | if (axis === 'x') {
|
227 |
|
228 | if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
|
229 |
|
230 | else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
|
231 |
|
232 | else curTransform = parseFloat(matrix[4]);
|
233 | }
|
234 | if (axis === 'y') {
|
235 |
|
236 | if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
|
237 |
|
238 | else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
|
239 |
|
240 | else curTransform = parseFloat(matrix[5]);
|
241 | }
|
242 | return curTransform || 0;
|
243 | }
|
244 | function isObject$1(o) {
|
245 | return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
|
246 | }
|
247 | function isNode(node) {
|
248 |
|
249 | if (typeof window !== 'undefined' && typeof window.HTMLElement !== 'undefined') {
|
250 | return node instanceof HTMLElement;
|
251 | }
|
252 | return node && (node.nodeType === 1 || node.nodeType === 11);
|
253 | }
|
254 | function extend$1() {
|
255 | const to = Object(arguments.length <= 0 ? undefined : arguments[0]);
|
256 | const noExtend = ['__proto__', 'constructor', 'prototype'];
|
257 | for (let i = 1; i < arguments.length; i += 1) {
|
258 | const nextSource = i < 0 || arguments.length <= i ? undefined : arguments[i];
|
259 | if (nextSource !== undefined && nextSource !== null && !isNode(nextSource)) {
|
260 | const keysArray = Object.keys(Object(nextSource)).filter(key => noExtend.indexOf(key) < 0);
|
261 | for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
|
262 | const nextKey = keysArray[nextIndex];
|
263 | const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
264 | if (desc !== undefined && desc.enumerable) {
|
265 | if (isObject$1(to[nextKey]) && isObject$1(nextSource[nextKey])) {
|
266 | if (nextSource[nextKey].__swiper__) {
|
267 | to[nextKey] = nextSource[nextKey];
|
268 | } else {
|
269 | extend$1(to[nextKey], nextSource[nextKey]);
|
270 | }
|
271 | } else if (!isObject$1(to[nextKey]) && isObject$1(nextSource[nextKey])) {
|
272 | to[nextKey] = {};
|
273 | if (nextSource[nextKey].__swiper__) {
|
274 | to[nextKey] = nextSource[nextKey];
|
275 | } else {
|
276 | extend$1(to[nextKey], nextSource[nextKey]);
|
277 | }
|
278 | } else {
|
279 | to[nextKey] = nextSource[nextKey];
|
280 | }
|
281 | }
|
282 | }
|
283 | }
|
284 | }
|
285 | return to;
|
286 | }
|
287 | function setCSSProperty(el, varName, varValue) {
|
288 | el.style.setProperty(varName, varValue);
|
289 | }
|
290 | function animateCSSModeScroll(_ref) {
|
291 | let {
|
292 | swiper,
|
293 | targetPosition,
|
294 | side
|
295 | } = _ref;
|
296 | const window = getWindow();
|
297 | const startPosition = -swiper.translate;
|
298 | let startTime = null;
|
299 | let time;
|
300 | const duration = swiper.params.speed;
|
301 | swiper.wrapperEl.style.scrollSnapType = 'none';
|
302 | window.cancelAnimationFrame(swiper.cssModeFrameID);
|
303 | const dir = targetPosition > startPosition ? 'next' : 'prev';
|
304 | const isOutOfBound = (current, target) => {
|
305 | return dir === 'next' && current >= target || dir === 'prev' && current <= target;
|
306 | };
|
307 | const animate = () => {
|
308 | time = new Date().getTime();
|
309 | if (startTime === null) {
|
310 | startTime = time;
|
311 | }
|
312 | const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
|
313 | const easeProgress = 0.5 - Math.cos(progress * Math.PI) / 2;
|
314 | let currentPosition = startPosition + easeProgress * (targetPosition - startPosition);
|
315 | if (isOutOfBound(currentPosition, targetPosition)) {
|
316 | currentPosition = targetPosition;
|
317 | }
|
318 | swiper.wrapperEl.scrollTo({
|
319 | [side]: currentPosition
|
320 | });
|
321 | if (isOutOfBound(currentPosition, targetPosition)) {
|
322 | swiper.wrapperEl.style.overflow = 'hidden';
|
323 | swiper.wrapperEl.style.scrollSnapType = '';
|
324 | setTimeout(() => {
|
325 | swiper.wrapperEl.style.overflow = '';
|
326 | swiper.wrapperEl.scrollTo({
|
327 | [side]: currentPosition
|
328 | });
|
329 | });
|
330 | window.cancelAnimationFrame(swiper.cssModeFrameID);
|
331 | return;
|
332 | }
|
333 | swiper.cssModeFrameID = window.requestAnimationFrame(animate);
|
334 | };
|
335 | animate();
|
336 | }
|
337 | function elementChildren(element, selector) {
|
338 | if (selector === void 0) {
|
339 | selector = '';
|
340 | }
|
341 | return [...element.children].filter(el => el.matches(selector));
|
342 | }
|
343 | function showWarning(text) {
|
344 | try {
|
345 | console.warn(text);
|
346 | return;
|
347 | } catch (err) {
|
348 |
|
349 | }
|
350 | }
|
351 | function createElement(tag, classes) {
|
352 | if (classes === void 0) {
|
353 | classes = [];
|
354 | }
|
355 | const el = document.createElement(tag);
|
356 | el.classList.add(...(Array.isArray(classes) ? classes : classesToTokens(classes)));
|
357 | return el;
|
358 | }
|
359 | function elementPrevAll(el, selector) {
|
360 | const prevEls = [];
|
361 | while (el.previousElementSibling) {
|
362 | const prev = el.previousElementSibling;
|
363 | if (selector) {
|
364 | if (prev.matches(selector)) prevEls.push(prev);
|
365 | } else prevEls.push(prev);
|
366 | el = prev;
|
367 | }
|
368 | return prevEls;
|
369 | }
|
370 | function elementNextAll(el, selector) {
|
371 | const nextEls = [];
|
372 | while (el.nextElementSibling) {
|
373 | const next = el.nextElementSibling;
|
374 | if (selector) {
|
375 | if (next.matches(selector)) nextEls.push(next);
|
376 | } else nextEls.push(next);
|
377 | el = next;
|
378 | }
|
379 | return nextEls;
|
380 | }
|
381 | function elementStyle(el, prop) {
|
382 | const window = getWindow();
|
383 | return window.getComputedStyle(el, null).getPropertyValue(prop);
|
384 | }
|
385 | function elementIndex(el) {
|
386 | let child = el;
|
387 | let i;
|
388 | if (child) {
|
389 | i = 0;
|
390 |
|
391 | while ((child = child.previousSibling) !== null) {
|
392 | if (child.nodeType === 1) i += 1;
|
393 | }
|
394 | return i;
|
395 | }
|
396 | return undefined;
|
397 | }
|
398 | function elementParents(el, selector) {
|
399 | const parents = [];
|
400 | let parent = el.parentElement;
|
401 | while (parent) {
|
402 | if (selector) {
|
403 | if (parent.matches(selector)) parents.push(parent);
|
404 | } else {
|
405 | parents.push(parent);
|
406 | }
|
407 | parent = parent.parentElement;
|
408 | }
|
409 | return parents;
|
410 | }
|
411 | function elementOuterSize(el, size, includeMargins) {
|
412 | const window = getWindow();
|
413 | if (includeMargins) {
|
414 | 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'));
|
415 | }
|
416 | return el.offsetWidth;
|
417 | }
|
418 |
|
419 | let support;
|
420 | function calcSupport() {
|
421 | const window = getWindow();
|
422 | const document = getDocument();
|
423 | return {
|
424 | smoothScroll: document.documentElement && document.documentElement.style && 'scrollBehavior' in document.documentElement.style,
|
425 | touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch)
|
426 | };
|
427 | }
|
428 | function getSupport() {
|
429 | if (!support) {
|
430 | support = calcSupport();
|
431 | }
|
432 | return support;
|
433 | }
|
434 |
|
435 | let deviceCached;
|
436 | function calcDevice(_temp) {
|
437 | let {
|
438 | userAgent
|
439 | } = _temp === void 0 ? {} : _temp;
|
440 | const support = getSupport();
|
441 | const window = getWindow();
|
442 | const platform = window.navigator.platform;
|
443 | const ua = userAgent || window.navigator.userAgent;
|
444 | const device = {
|
445 | ios: false,
|
446 | android: false
|
447 | };
|
448 | const screenWidth = window.screen.width;
|
449 | const screenHeight = window.screen.height;
|
450 | const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
|
451 | let ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
|
452 | const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
|
453 | const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
|
454 | const windows = platform === 'Win32';
|
455 | let macos = platform === 'MacIntel';
|
456 |
|
457 |
|
458 | const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
|
459 | if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) {
|
460 | ipad = ua.match(/(Version)\/([\d.]+)/);
|
461 | if (!ipad) ipad = [0, 1, '13_0_0'];
|
462 | macos = false;
|
463 | }
|
464 |
|
465 |
|
466 | if (android && !windows) {
|
467 | device.os = 'android';
|
468 | device.android = true;
|
469 | }
|
470 | if (ipad || iphone || ipod) {
|
471 | device.os = 'ios';
|
472 | device.ios = true;
|
473 | }
|
474 |
|
475 |
|
476 | return device;
|
477 | }
|
478 | function getDevice(overrides) {
|
479 | if (overrides === void 0) {
|
480 | overrides = {};
|
481 | }
|
482 | if (!deviceCached) {
|
483 | deviceCached = calcDevice(overrides);
|
484 | }
|
485 | return deviceCached;
|
486 | }
|
487 |
|
488 | let browser;
|
489 | function calcBrowser() {
|
490 | const window = getWindow();
|
491 | const device = getDevice();
|
492 | let needPerspectiveFix = false;
|
493 | function isSafari() {
|
494 | const ua = window.navigator.userAgent.toLowerCase();
|
495 | return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0;
|
496 | }
|
497 | if (isSafari()) {
|
498 | const ua = String(window.navigator.userAgent);
|
499 | if (ua.includes('Version/')) {
|
500 | const [major, minor] = ua.split('Version/')[1].split(' ')[0].split('.').map(num => Number(num));
|
501 | needPerspectiveFix = major < 16 || major === 16 && minor < 2;
|
502 | }
|
503 | }
|
504 | const isWebView = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent);
|
505 | const isSafariBrowser = isSafari();
|
506 | const need3dFix = isSafariBrowser || isWebView && device.ios;
|
507 | return {
|
508 | isSafari: needPerspectiveFix || isSafariBrowser,
|
509 | needPerspectiveFix,
|
510 | need3dFix,
|
511 | isWebView
|
512 | };
|
513 | }
|
514 | function getBrowser() {
|
515 | if (!browser) {
|
516 | browser = calcBrowser();
|
517 | }
|
518 | return browser;
|
519 | }
|
520 |
|
521 | function Resize(_ref) {
|
522 | let {
|
523 | swiper,
|
524 | on,
|
525 | emit
|
526 | } = _ref;
|
527 | const window = getWindow();
|
528 | let observer = null;
|
529 | let animationFrame = null;
|
530 | const resizeHandler = () => {
|
531 | if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
532 | emit('beforeResize');
|
533 | emit('resize');
|
534 | };
|
535 | const createObserver = () => {
|
536 | if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
537 | observer = new ResizeObserver(entries => {
|
538 | animationFrame = window.requestAnimationFrame(() => {
|
539 | const {
|
540 | width,
|
541 | height
|
542 | } = swiper;
|
543 | let newWidth = width;
|
544 | let newHeight = height;
|
545 | entries.forEach(_ref2 => {
|
546 | let {
|
547 | contentBoxSize,
|
548 | contentRect,
|
549 | target
|
550 | } = _ref2;
|
551 | if (target && target !== swiper.el) return;
|
552 | newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
|
553 | newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
|
554 | });
|
555 | if (newWidth !== width || newHeight !== height) {
|
556 | resizeHandler();
|
557 | }
|
558 | });
|
559 | });
|
560 | observer.observe(swiper.el);
|
561 | };
|
562 | const removeObserver = () => {
|
563 | if (animationFrame) {
|
564 | window.cancelAnimationFrame(animationFrame);
|
565 | }
|
566 | if (observer && observer.unobserve && swiper.el) {
|
567 | observer.unobserve(swiper.el);
|
568 | observer = null;
|
569 | }
|
570 | };
|
571 | const orientationChangeHandler = () => {
|
572 | if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
573 | emit('orientationchange');
|
574 | };
|
575 | on('init', () => {
|
576 | if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
|
577 | createObserver();
|
578 | return;
|
579 | }
|
580 | window.addEventListener('resize', resizeHandler);
|
581 | window.addEventListener('orientationchange', orientationChangeHandler);
|
582 | });
|
583 | on('destroy', () => {
|
584 | removeObserver();
|
585 | window.removeEventListener('resize', resizeHandler);
|
586 | window.removeEventListener('orientationchange', orientationChangeHandler);
|
587 | });
|
588 | }
|
589 |
|
590 | function Observer(_ref) {
|
591 | let {
|
592 | swiper,
|
593 | extendParams,
|
594 | on,
|
595 | emit
|
596 | } = _ref;
|
597 | const observers = [];
|
598 | const window = getWindow();
|
599 | const attach = function (target, options) {
|
600 | if (options === void 0) {
|
601 | options = {};
|
602 | }
|
603 | const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
|
604 | const observer = new ObserverFunc(mutations => {
|
605 |
|
606 |
|
607 |
|
608 | if (swiper.__preventObserver__) return;
|
609 | if (mutations.length === 1) {
|
610 | emit('observerUpdate', mutations[0]);
|
611 | return;
|
612 | }
|
613 | const observerUpdate = function observerUpdate() {
|
614 | emit('observerUpdate', mutations[0]);
|
615 | };
|
616 | if (window.requestAnimationFrame) {
|
617 | window.requestAnimationFrame(observerUpdate);
|
618 | } else {
|
619 | window.setTimeout(observerUpdate, 0);
|
620 | }
|
621 | });
|
622 | observer.observe(target, {
|
623 | attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
|
624 | childList: typeof options.childList === 'undefined' ? true : options.childList,
|
625 | characterData: typeof options.characterData === 'undefined' ? true : options.characterData
|
626 | });
|
627 | observers.push(observer);
|
628 | };
|
629 | const init = () => {
|
630 | if (!swiper.params.observer) return;
|
631 | if (swiper.params.observeParents) {
|
632 | const containerParents = elementParents(swiper.hostEl);
|
633 | for (let i = 0; i < containerParents.length; i += 1) {
|
634 | attach(containerParents[i]);
|
635 | }
|
636 | }
|
637 |
|
638 | attach(swiper.hostEl, {
|
639 | childList: swiper.params.observeSlideChildren
|
640 | });
|
641 |
|
642 |
|
643 | attach(swiper.wrapperEl, {
|
644 | attributes: false
|
645 | });
|
646 | };
|
647 | const destroy = () => {
|
648 | observers.forEach(observer => {
|
649 | observer.disconnect();
|
650 | });
|
651 | observers.splice(0, observers.length);
|
652 | };
|
653 | extendParams({
|
654 | observer: false,
|
655 | observeParents: false,
|
656 | observeSlideChildren: false
|
657 | });
|
658 | on('init', init);
|
659 | on('destroy', destroy);
|
660 | }
|
661 |
|
662 |
|
663 |
|
664 | var eventsEmitter = {
|
665 | on(events, handler, priority) {
|
666 | const self = this;
|
667 | if (!self.eventsListeners || self.destroyed) return self;
|
668 | if (typeof handler !== 'function') return self;
|
669 | const method = priority ? 'unshift' : 'push';
|
670 | events.split(' ').forEach(event => {
|
671 | if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
|
672 | self.eventsListeners[event][method](handler);
|
673 | });
|
674 | return self;
|
675 | },
|
676 | once(events, handler, priority) {
|
677 | const self = this;
|
678 | if (!self.eventsListeners || self.destroyed) return self;
|
679 | if (typeof handler !== 'function') return self;
|
680 | function onceHandler() {
|
681 | self.off(events, onceHandler);
|
682 | if (onceHandler.__emitterProxy) {
|
683 | delete onceHandler.__emitterProxy;
|
684 | }
|
685 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
686 | args[_key] = arguments[_key];
|
687 | }
|
688 | handler.apply(self, args);
|
689 | }
|
690 | onceHandler.__emitterProxy = handler;
|
691 | return self.on(events, onceHandler, priority);
|
692 | },
|
693 | onAny(handler, priority) {
|
694 | const self = this;
|
695 | if (!self.eventsListeners || self.destroyed) return self;
|
696 | if (typeof handler !== 'function') return self;
|
697 | const method = priority ? 'unshift' : 'push';
|
698 | if (self.eventsAnyListeners.indexOf(handler) < 0) {
|
699 | self.eventsAnyListeners[method](handler);
|
700 | }
|
701 | return self;
|
702 | },
|
703 | offAny(handler) {
|
704 | const self = this;
|
705 | if (!self.eventsListeners || self.destroyed) return self;
|
706 | if (!self.eventsAnyListeners) return self;
|
707 | const index = self.eventsAnyListeners.indexOf(handler);
|
708 | if (index >= 0) {
|
709 | self.eventsAnyListeners.splice(index, 1);
|
710 | }
|
711 | return self;
|
712 | },
|
713 | off(events, handler) {
|
714 | const self = this;
|
715 | if (!self.eventsListeners || self.destroyed) return self;
|
716 | if (!self.eventsListeners) return self;
|
717 | events.split(' ').forEach(event => {
|
718 | if (typeof handler === 'undefined') {
|
719 | self.eventsListeners[event] = [];
|
720 | } else if (self.eventsListeners[event]) {
|
721 | self.eventsListeners[event].forEach((eventHandler, index) => {
|
722 | if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) {
|
723 | self.eventsListeners[event].splice(index, 1);
|
724 | }
|
725 | });
|
726 | }
|
727 | });
|
728 | return self;
|
729 | },
|
730 | emit() {
|
731 | const self = this;
|
732 | if (!self.eventsListeners || self.destroyed) return self;
|
733 | if (!self.eventsListeners) return self;
|
734 | let events;
|
735 | let data;
|
736 | let context;
|
737 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
738 | args[_key2] = arguments[_key2];
|
739 | }
|
740 | if (typeof args[0] === 'string' || Array.isArray(args[0])) {
|
741 | events = args[0];
|
742 | data = args.slice(1, args.length);
|
743 | context = self;
|
744 | } else {
|
745 | events = args[0].events;
|
746 | data = args[0].data;
|
747 | context = args[0].context || self;
|
748 | }
|
749 | data.unshift(context);
|
750 | const eventsArray = Array.isArray(events) ? events : events.split(' ');
|
751 | eventsArray.forEach(event => {
|
752 | if (self.eventsAnyListeners && self.eventsAnyListeners.length) {
|
753 | self.eventsAnyListeners.forEach(eventHandler => {
|
754 | eventHandler.apply(context, [event, ...data]);
|
755 | });
|
756 | }
|
757 | if (self.eventsListeners && self.eventsListeners[event]) {
|
758 | self.eventsListeners[event].forEach(eventHandler => {
|
759 | eventHandler.apply(context, data);
|
760 | });
|
761 | }
|
762 | });
|
763 | return self;
|
764 | }
|
765 | };
|
766 |
|
767 | function updateSize() {
|
768 | const swiper = this;
|
769 | let width;
|
770 | let height;
|
771 | const el = swiper.el;
|
772 | if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
|
773 | width = swiper.params.width;
|
774 | } else {
|
775 | width = el.clientWidth;
|
776 | }
|
777 | if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
|
778 | height = swiper.params.height;
|
779 | } else {
|
780 | height = el.clientHeight;
|
781 | }
|
782 | if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
|
783 | return;
|
784 | }
|
785 |
|
786 |
|
787 | width = width - parseInt(elementStyle(el, 'padding-left') || 0, 10) - parseInt(elementStyle(el, 'padding-right') || 0, 10);
|
788 | height = height - parseInt(elementStyle(el, 'padding-top') || 0, 10) - parseInt(elementStyle(el, 'padding-bottom') || 0, 10);
|
789 | if (Number.isNaN(width)) width = 0;
|
790 | if (Number.isNaN(height)) height = 0;
|
791 | Object.assign(swiper, {
|
792 | width,
|
793 | height,
|
794 | size: swiper.isHorizontal() ? width : height
|
795 | });
|
796 | }
|
797 |
|
798 | function updateSlides() {
|
799 | const swiper = this;
|
800 | function getDirectionPropertyValue(node, label) {
|
801 | return parseFloat(node.getPropertyValue(swiper.getDirectionLabel(label)) || 0);
|
802 | }
|
803 | const params = swiper.params;
|
804 | const {
|
805 | wrapperEl,
|
806 | slidesEl,
|
807 | size: swiperSize,
|
808 | rtlTranslate: rtl,
|
809 | wrongRTL
|
810 | } = swiper;
|
811 | const isVirtual = swiper.virtual && params.virtual.enabled;
|
812 | const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
|
813 | const slides = elementChildren(slidesEl, `.${swiper.params.slideClass}, swiper-slide`);
|
814 | const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
|
815 | let snapGrid = [];
|
816 | const slidesGrid = [];
|
817 | const slidesSizesGrid = [];
|
818 | let offsetBefore = params.slidesOffsetBefore;
|
819 | if (typeof offsetBefore === 'function') {
|
820 | offsetBefore = params.slidesOffsetBefore.call(swiper);
|
821 | }
|
822 | let offsetAfter = params.slidesOffsetAfter;
|
823 | if (typeof offsetAfter === 'function') {
|
824 | offsetAfter = params.slidesOffsetAfter.call(swiper);
|
825 | }
|
826 | const previousSnapGridLength = swiper.snapGrid.length;
|
827 | const previousSlidesGridLength = swiper.slidesGrid.length;
|
828 | let spaceBetween = params.spaceBetween;
|
829 | let slidePosition = -offsetBefore;
|
830 | let prevSlideSize = 0;
|
831 | let index = 0;
|
832 | if (typeof swiperSize === 'undefined') {
|
833 | return;
|
834 | }
|
835 | if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
|
836 | spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize;
|
837 | } else if (typeof spaceBetween === 'string') {
|
838 | spaceBetween = parseFloat(spaceBetween);
|
839 | }
|
840 | swiper.virtualSize = -spaceBetween;
|
841 |
|
842 |
|
843 | slides.forEach(slideEl => {
|
844 | if (rtl) {
|
845 | slideEl.style.marginLeft = '';
|
846 | } else {
|
847 | slideEl.style.marginRight = '';
|
848 | }
|
849 | slideEl.style.marginBottom = '';
|
850 | slideEl.style.marginTop = '';
|
851 | });
|
852 |
|
853 |
|
854 | if (params.centeredSlides && params.cssMode) {
|
855 | setCSSProperty(wrapperEl, '--swiper-centered-offset-before', '');
|
856 | setCSSProperty(wrapperEl, '--swiper-centered-offset-after', '');
|
857 | }
|
858 | const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid;
|
859 | if (gridEnabled) {
|
860 | swiper.grid.initSlides(slides);
|
861 | } else if (swiper.grid) {
|
862 | swiper.grid.unsetSlides();
|
863 | }
|
864 |
|
865 |
|
866 | let slideSize;
|
867 | const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => {
|
868 | return typeof params.breakpoints[key].slidesPerView !== 'undefined';
|
869 | }).length > 0;
|
870 | for (let i = 0; i < slidesLength; i += 1) {
|
871 | slideSize = 0;
|
872 | let slide;
|
873 | if (slides[i]) slide = slides[i];
|
874 | if (gridEnabled) {
|
875 | swiper.grid.updateSlide(i, slide, slides);
|
876 | }
|
877 | if (slides[i] && elementStyle(slide, 'display') === 'none') continue;
|
878 |
|
879 | if (params.slidesPerView === 'auto') {
|
880 | if (shouldResetSlideSize) {
|
881 | slides[i].style[swiper.getDirectionLabel('width')] = ``;
|
882 | }
|
883 | const slideStyles = getComputedStyle(slide);
|
884 | const currentTransform = slide.style.transform;
|
885 | const currentWebKitTransform = slide.style.webkitTransform;
|
886 | if (currentTransform) {
|
887 | slide.style.transform = 'none';
|
888 | }
|
889 | if (currentWebKitTransform) {
|
890 | slide.style.webkitTransform = 'none';
|
891 | }
|
892 | if (params.roundLengths) {
|
893 | slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
|
894 | } else {
|
895 |
|
896 | const width = getDirectionPropertyValue(slideStyles, 'width');
|
897 | const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left');
|
898 | const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right');
|
899 | const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left');
|
900 | const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right');
|
901 | const boxSizing = slideStyles.getPropertyValue('box-sizing');
|
902 | if (boxSizing && boxSizing === 'border-box') {
|
903 | slideSize = width + marginLeft + marginRight;
|
904 | } else {
|
905 | const {
|
906 | clientWidth,
|
907 | offsetWidth
|
908 | } = slide;
|
909 | slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
|
910 | }
|
911 | }
|
912 | if (currentTransform) {
|
913 | slide.style.transform = currentTransform;
|
914 | }
|
915 | if (currentWebKitTransform) {
|
916 | slide.style.webkitTransform = currentWebKitTransform;
|
917 | }
|
918 | if (params.roundLengths) slideSize = Math.floor(slideSize);
|
919 | } else {
|
920 | slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
|
921 | if (params.roundLengths) slideSize = Math.floor(slideSize);
|
922 | if (slides[i]) {
|
923 | slides[i].style[swiper.getDirectionLabel('width')] = `${slideSize}px`;
|
924 | }
|
925 | }
|
926 | if (slides[i]) {
|
927 | slides[i].swiperSlideSize = slideSize;
|
928 | }
|
929 | slidesSizesGrid.push(slideSize);
|
930 | if (params.centeredSlides) {
|
931 | slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
|
932 | if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
|
933 | if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
|
934 | if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
|
935 | if (params.roundLengths) slidePosition = Math.floor(slidePosition);
|
936 | if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
|
937 | slidesGrid.push(slidePosition);
|
938 | } else {
|
939 | if (params.roundLengths) slidePosition = Math.floor(slidePosition);
|
940 | if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
|
941 | slidesGrid.push(slidePosition);
|
942 | slidePosition = slidePosition + slideSize + spaceBetween;
|
943 | }
|
944 | swiper.virtualSize += slideSize + spaceBetween;
|
945 | prevSlideSize = slideSize;
|
946 | index += 1;
|
947 | }
|
948 | swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
|
949 | if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
|
950 | wrapperEl.style.width = `${swiper.virtualSize + spaceBetween}px`;
|
951 | }
|
952 | if (params.setWrapperSize) {
|
953 | wrapperEl.style[swiper.getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
|
954 | }
|
955 | if (gridEnabled) {
|
956 | swiper.grid.updateWrapperSize(slideSize, snapGrid);
|
957 | }
|
958 |
|
959 |
|
960 | if (!params.centeredSlides) {
|
961 | const newSlidesGrid = [];
|
962 | for (let i = 0; i < snapGrid.length; i += 1) {
|
963 | let slidesGridItem = snapGrid[i];
|
964 | if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
|
965 | if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
|
966 | newSlidesGrid.push(slidesGridItem);
|
967 | }
|
968 | }
|
969 | snapGrid = newSlidesGrid;
|
970 | if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
|
971 | snapGrid.push(swiper.virtualSize - swiperSize);
|
972 | }
|
973 | }
|
974 | if (isVirtual && params.loop) {
|
975 | const size = slidesSizesGrid[0] + spaceBetween;
|
976 | if (params.slidesPerGroup > 1) {
|
977 | const groups = Math.ceil((swiper.virtual.slidesBefore + swiper.virtual.slidesAfter) / params.slidesPerGroup);
|
978 | const groupSize = size * params.slidesPerGroup;
|
979 | for (let i = 0; i < groups; i += 1) {
|
980 | snapGrid.push(snapGrid[snapGrid.length - 1] + groupSize);
|
981 | }
|
982 | }
|
983 | for (let i = 0; i < swiper.virtual.slidesBefore + swiper.virtual.slidesAfter; i += 1) {
|
984 | if (params.slidesPerGroup === 1) {
|
985 | snapGrid.push(snapGrid[snapGrid.length - 1] + size);
|
986 | }
|
987 | slidesGrid.push(slidesGrid[slidesGrid.length - 1] + size);
|
988 | swiper.virtualSize += size;
|
989 | }
|
990 | }
|
991 | if (snapGrid.length === 0) snapGrid = [0];
|
992 | if (spaceBetween !== 0) {
|
993 | const key = swiper.isHorizontal() && rtl ? 'marginLeft' : swiper.getDirectionLabel('marginRight');
|
994 | slides.filter((_, slideIndex) => {
|
995 | if (!params.cssMode || params.loop) return true;
|
996 | if (slideIndex === slides.length - 1) {
|
997 | return false;
|
998 | }
|
999 | return true;
|
1000 | }).forEach(slideEl => {
|
1001 | slideEl.style[key] = `${spaceBetween}px`;
|
1002 | });
|
1003 | }
|
1004 | if (params.centeredSlides && params.centeredSlidesBounds) {
|
1005 | let allSlidesSize = 0;
|
1006 | slidesSizesGrid.forEach(slideSizeValue => {
|
1007 | allSlidesSize += slideSizeValue + (spaceBetween || 0);
|
1008 | });
|
1009 | allSlidesSize -= spaceBetween;
|
1010 | const maxSnap = allSlidesSize - swiperSize;
|
1011 | snapGrid = snapGrid.map(snap => {
|
1012 | if (snap <= 0) return -offsetBefore;
|
1013 | if (snap > maxSnap) return maxSnap + offsetAfter;
|
1014 | return snap;
|
1015 | });
|
1016 | }
|
1017 | if (params.centerInsufficientSlides) {
|
1018 | let allSlidesSize = 0;
|
1019 | slidesSizesGrid.forEach(slideSizeValue => {
|
1020 | allSlidesSize += slideSizeValue + (spaceBetween || 0);
|
1021 | });
|
1022 | allSlidesSize -= spaceBetween;
|
1023 | const offsetSize = (params.slidesOffsetBefore || 0) + (params.slidesOffsetAfter || 0);
|
1024 | if (allSlidesSize + offsetSize < swiperSize) {
|
1025 | const allSlidesOffset = (swiperSize - allSlidesSize - offsetSize) / 2;
|
1026 | snapGrid.forEach((snap, snapIndex) => {
|
1027 | snapGrid[snapIndex] = snap - allSlidesOffset;
|
1028 | });
|
1029 | slidesGrid.forEach((snap, snapIndex) => {
|
1030 | slidesGrid[snapIndex] = snap + allSlidesOffset;
|
1031 | });
|
1032 | }
|
1033 | }
|
1034 | Object.assign(swiper, {
|
1035 | slides,
|
1036 | snapGrid,
|
1037 | slidesGrid,
|
1038 | slidesSizesGrid
|
1039 | });
|
1040 | if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) {
|
1041 | setCSSProperty(wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`);
|
1042 | setCSSProperty(wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`);
|
1043 | const addToSnapGrid = -swiper.snapGrid[0];
|
1044 | const addToSlidesGrid = -swiper.slidesGrid[0];
|
1045 | swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid);
|
1046 | swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid);
|
1047 | }
|
1048 | if (slidesLength !== previousSlidesLength) {
|
1049 | swiper.emit('slidesLengthChange');
|
1050 | }
|
1051 | if (snapGrid.length !== previousSnapGridLength) {
|
1052 | if (swiper.params.watchOverflow) swiper.checkOverflow();
|
1053 | swiper.emit('snapGridLengthChange');
|
1054 | }
|
1055 | if (slidesGrid.length !== previousSlidesGridLength) {
|
1056 | swiper.emit('slidesGridLengthChange');
|
1057 | }
|
1058 | if (params.watchSlidesProgress) {
|
1059 | swiper.updateSlidesOffset();
|
1060 | }
|
1061 | swiper.emit('slidesUpdated');
|
1062 | if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
|
1063 | const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`;
|
1064 | const hasClassBackfaceClassAdded = swiper.el.classList.contains(backFaceHiddenClass);
|
1065 | if (slidesLength <= params.maxBackfaceHiddenSlides) {
|
1066 | if (!hasClassBackfaceClassAdded) swiper.el.classList.add(backFaceHiddenClass);
|
1067 | } else if (hasClassBackfaceClassAdded) {
|
1068 | swiper.el.classList.remove(backFaceHiddenClass);
|
1069 | }
|
1070 | }
|
1071 | }
|
1072 |
|
1073 | function updateAutoHeight(speed) {
|
1074 | const swiper = this;
|
1075 | const activeSlides = [];
|
1076 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
1077 | let newHeight = 0;
|
1078 | let i;
|
1079 | if (typeof speed === 'number') {
|
1080 | swiper.setTransition(speed);
|
1081 | } else if (speed === true) {
|
1082 | swiper.setTransition(swiper.params.speed);
|
1083 | }
|
1084 | const getSlideByIndex = index => {
|
1085 | if (isVirtual) {
|
1086 | return swiper.slides[swiper.getSlideIndexByData(index)];
|
1087 | }
|
1088 | return swiper.slides[index];
|
1089 | };
|
1090 |
|
1091 | if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
|
1092 | if (swiper.params.centeredSlides) {
|
1093 | (swiper.visibleSlides || []).forEach(slide => {
|
1094 | activeSlides.push(slide);
|
1095 | });
|
1096 | } else {
|
1097 | for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
|
1098 | const index = swiper.activeIndex + i;
|
1099 | if (index > swiper.slides.length && !isVirtual) break;
|
1100 | activeSlides.push(getSlideByIndex(index));
|
1101 | }
|
1102 | }
|
1103 | } else {
|
1104 | activeSlides.push(getSlideByIndex(swiper.activeIndex));
|
1105 | }
|
1106 |
|
1107 |
|
1108 | for (i = 0; i < activeSlides.length; i += 1) {
|
1109 | if (typeof activeSlides[i] !== 'undefined') {
|
1110 | const height = activeSlides[i].offsetHeight;
|
1111 | newHeight = height > newHeight ? height : newHeight;
|
1112 | }
|
1113 | }
|
1114 |
|
1115 |
|
1116 | if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
|
1117 | }
|
1118 |
|
1119 | function updateSlidesOffset() {
|
1120 | const swiper = this;
|
1121 | const slides = swiper.slides;
|
1122 |
|
1123 | const minusOffset = swiper.isElement ? swiper.isHorizontal() ? swiper.wrapperEl.offsetLeft : swiper.wrapperEl.offsetTop : 0;
|
1124 | for (let i = 0; i < slides.length; i += 1) {
|
1125 | slides[i].swiperSlideOffset = (swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop) - minusOffset - swiper.cssOverflowAdjustment();
|
1126 | }
|
1127 | }
|
1128 |
|
1129 | const toggleSlideClasses$1 = (slideEl, condition, className) => {
|
1130 | if (condition && !slideEl.classList.contains(className)) {
|
1131 | slideEl.classList.add(className);
|
1132 | } else if (!condition && slideEl.classList.contains(className)) {
|
1133 | slideEl.classList.remove(className);
|
1134 | }
|
1135 | };
|
1136 | function updateSlidesProgress(translate) {
|
1137 | if (translate === void 0) {
|
1138 | translate = this && this.translate || 0;
|
1139 | }
|
1140 | const swiper = this;
|
1141 | const params = swiper.params;
|
1142 | const {
|
1143 | slides,
|
1144 | rtlTranslate: rtl,
|
1145 | snapGrid
|
1146 | } = swiper;
|
1147 | if (slides.length === 0) return;
|
1148 | if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
|
1149 | let offsetCenter = -translate;
|
1150 | if (rtl) offsetCenter = translate;
|
1151 | swiper.visibleSlidesIndexes = [];
|
1152 | swiper.visibleSlides = [];
|
1153 | let spaceBetween = params.spaceBetween;
|
1154 | if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
|
1155 | spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiper.size;
|
1156 | } else if (typeof spaceBetween === 'string') {
|
1157 | spaceBetween = parseFloat(spaceBetween);
|
1158 | }
|
1159 | for (let i = 0; i < slides.length; i += 1) {
|
1160 | const slide = slides[i];
|
1161 | let slideOffset = slide.swiperSlideOffset;
|
1162 | if (params.cssMode && params.centeredSlides) {
|
1163 | slideOffset -= slides[0].swiperSlideOffset;
|
1164 | }
|
1165 | const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
|
1166 | const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
|
1167 | const slideBefore = -(offsetCenter - slideOffset);
|
1168 | const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
|
1169 | const isFullyVisible = slideBefore >= 0 && slideBefore <= swiper.size - swiper.slidesSizesGrid[i];
|
1170 | const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size;
|
1171 | if (isVisible) {
|
1172 | swiper.visibleSlides.push(slide);
|
1173 | swiper.visibleSlidesIndexes.push(i);
|
1174 | }
|
1175 | toggleSlideClasses$1(slide, isVisible, params.slideVisibleClass);
|
1176 | toggleSlideClasses$1(slide, isFullyVisible, params.slideFullyVisibleClass);
|
1177 | slide.progress = rtl ? -slideProgress : slideProgress;
|
1178 | slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress;
|
1179 | }
|
1180 | }
|
1181 |
|
1182 | function updateProgress(translate) {
|
1183 | const swiper = this;
|
1184 | if (typeof translate === 'undefined') {
|
1185 | const multiplier = swiper.rtlTranslate ? -1 : 1;
|
1186 |
|
1187 | translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
|
1188 | }
|
1189 | const params = swiper.params;
|
1190 | const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
1191 | let {
|
1192 | progress,
|
1193 | isBeginning,
|
1194 | isEnd,
|
1195 | progressLoop
|
1196 | } = swiper;
|
1197 | const wasBeginning = isBeginning;
|
1198 | const wasEnd = isEnd;
|
1199 | if (translatesDiff === 0) {
|
1200 | progress = 0;
|
1201 | isBeginning = true;
|
1202 | isEnd = true;
|
1203 | } else {
|
1204 | progress = (translate - swiper.minTranslate()) / translatesDiff;
|
1205 | const isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1;
|
1206 | const isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1;
|
1207 | isBeginning = isBeginningRounded || progress <= 0;
|
1208 | isEnd = isEndRounded || progress >= 1;
|
1209 | if (isBeginningRounded) progress = 0;
|
1210 | if (isEndRounded) progress = 1;
|
1211 | }
|
1212 | if (params.loop) {
|
1213 | const firstSlideIndex = swiper.getSlideIndexByData(0);
|
1214 | const lastSlideIndex = swiper.getSlideIndexByData(swiper.slides.length - 1);
|
1215 | const firstSlideTranslate = swiper.slidesGrid[firstSlideIndex];
|
1216 | const lastSlideTranslate = swiper.slidesGrid[lastSlideIndex];
|
1217 | const translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1];
|
1218 | const translateAbs = Math.abs(translate);
|
1219 | if (translateAbs >= firstSlideTranslate) {
|
1220 | progressLoop = (translateAbs - firstSlideTranslate) / translateMax;
|
1221 | } else {
|
1222 | progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax;
|
1223 | }
|
1224 | if (progressLoop > 1) progressLoop -= 1;
|
1225 | }
|
1226 | Object.assign(swiper, {
|
1227 | progress,
|
1228 | progressLoop,
|
1229 | isBeginning,
|
1230 | isEnd
|
1231 | });
|
1232 | if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
|
1233 | if (isBeginning && !wasBeginning) {
|
1234 | swiper.emit('reachBeginning toEdge');
|
1235 | }
|
1236 | if (isEnd && !wasEnd) {
|
1237 | swiper.emit('reachEnd toEdge');
|
1238 | }
|
1239 | if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
|
1240 | swiper.emit('fromEdge');
|
1241 | }
|
1242 | swiper.emit('progress', progress);
|
1243 | }
|
1244 |
|
1245 | const toggleSlideClasses = (slideEl, condition, className) => {
|
1246 | if (condition && !slideEl.classList.contains(className)) {
|
1247 | slideEl.classList.add(className);
|
1248 | } else if (!condition && slideEl.classList.contains(className)) {
|
1249 | slideEl.classList.remove(className);
|
1250 | }
|
1251 | };
|
1252 | function updateSlidesClasses() {
|
1253 | const swiper = this;
|
1254 | const {
|
1255 | slides,
|
1256 | params,
|
1257 | slidesEl,
|
1258 | activeIndex
|
1259 | } = swiper;
|
1260 | const isVirtual = swiper.virtual && params.virtual.enabled;
|
1261 | const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
1262 | const getFilteredSlide = selector => {
|
1263 | return elementChildren(slidesEl, `.${params.slideClass}${selector}, swiper-slide${selector}`)[0];
|
1264 | };
|
1265 | let activeSlide;
|
1266 | let prevSlide;
|
1267 | let nextSlide;
|
1268 | if (isVirtual) {
|
1269 | if (params.loop) {
|
1270 | let slideIndex = activeIndex - swiper.virtual.slidesBefore;
|
1271 | if (slideIndex < 0) slideIndex = swiper.virtual.slides.length + slideIndex;
|
1272 | if (slideIndex >= swiper.virtual.slides.length) slideIndex -= swiper.virtual.slides.length;
|
1273 | activeSlide = getFilteredSlide(`[data-swiper-slide-index="${slideIndex}"]`);
|
1274 | } else {
|
1275 | activeSlide = getFilteredSlide(`[data-swiper-slide-index="${activeIndex}"]`);
|
1276 | }
|
1277 | } else {
|
1278 | if (gridEnabled) {
|
1279 | activeSlide = slides.filter(slideEl => slideEl.column === activeIndex)[0];
|
1280 | nextSlide = slides.filter(slideEl => slideEl.column === activeIndex + 1)[0];
|
1281 | prevSlide = slides.filter(slideEl => slideEl.column === activeIndex - 1)[0];
|
1282 | } else {
|
1283 | activeSlide = slides[activeIndex];
|
1284 | }
|
1285 | }
|
1286 | if (activeSlide) {
|
1287 | if (!gridEnabled) {
|
1288 |
|
1289 | nextSlide = elementNextAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
|
1290 | if (params.loop && !nextSlide) {
|
1291 | nextSlide = slides[0];
|
1292 | }
|
1293 |
|
1294 |
|
1295 | prevSlide = elementPrevAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
|
1296 | if (params.loop && !prevSlide === 0) {
|
1297 | prevSlide = slides[slides.length - 1];
|
1298 | }
|
1299 | }
|
1300 | }
|
1301 | slides.forEach(slideEl => {
|
1302 | toggleSlideClasses(slideEl, slideEl === activeSlide, params.slideActiveClass);
|
1303 | toggleSlideClasses(slideEl, slideEl === nextSlide, params.slideNextClass);
|
1304 | toggleSlideClasses(slideEl, slideEl === prevSlide, params.slidePrevClass);
|
1305 | });
|
1306 | swiper.emitSlidesClasses();
|
1307 | }
|
1308 |
|
1309 | const processLazyPreloader = (swiper, imageEl) => {
|
1310 | if (!swiper || swiper.destroyed || !swiper.params) return;
|
1311 | const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`;
|
1312 | const slideEl = imageEl.closest(slideSelector());
|
1313 | if (slideEl) {
|
1314 | let lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
|
1315 | if (!lazyEl && swiper.isElement) {
|
1316 | if (slideEl.shadowRoot) {
|
1317 | lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
|
1318 | } else {
|
1319 |
|
1320 | requestAnimationFrame(() => {
|
1321 | if (slideEl.shadowRoot) {
|
1322 | lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
|
1323 | if (lazyEl) lazyEl.remove();
|
1324 | }
|
1325 | });
|
1326 | }
|
1327 | }
|
1328 | if (lazyEl) lazyEl.remove();
|
1329 | }
|
1330 | };
|
1331 | const unlazy = (swiper, index) => {
|
1332 | if (!swiper.slides[index]) return;
|
1333 | const imageEl = swiper.slides[index].querySelector('[loading="lazy"]');
|
1334 | if (imageEl) imageEl.removeAttribute('loading');
|
1335 | };
|
1336 | const preload = swiper => {
|
1337 | if (!swiper || swiper.destroyed || !swiper.params) return;
|
1338 | let amount = swiper.params.lazyPreloadPrevNext;
|
1339 | const len = swiper.slides.length;
|
1340 | if (!len || !amount || amount < 0) return;
|
1341 | amount = Math.min(amount, len);
|
1342 | const slidesPerView = swiper.params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(swiper.params.slidesPerView);
|
1343 | const activeIndex = swiper.activeIndex;
|
1344 | if (swiper.params.grid && swiper.params.grid.rows > 1) {
|
1345 | const activeColumn = activeIndex;
|
1346 | const preloadColumns = [activeColumn - amount];
|
1347 | preloadColumns.push(...Array.from({
|
1348 | length: amount
|
1349 | }).map((_, i) => {
|
1350 | return activeColumn + slidesPerView + i;
|
1351 | }));
|
1352 | swiper.slides.forEach((slideEl, i) => {
|
1353 | if (preloadColumns.includes(slideEl.column)) unlazy(swiper, i);
|
1354 | });
|
1355 | return;
|
1356 | }
|
1357 | const slideIndexLastInView = activeIndex + slidesPerView - 1;
|
1358 | if (swiper.params.rewind || swiper.params.loop) {
|
1359 | for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {
|
1360 | const realIndex = (i % len + len) % len;
|
1361 | if (realIndex < activeIndex || realIndex > slideIndexLastInView) unlazy(swiper, realIndex);
|
1362 | }
|
1363 | } else {
|
1364 | for (let i = Math.max(activeIndex - amount, 0); i <= Math.min(slideIndexLastInView + amount, len - 1); i += 1) {
|
1365 | if (i !== activeIndex && (i > slideIndexLastInView || i < activeIndex)) {
|
1366 | unlazy(swiper, i);
|
1367 | }
|
1368 | }
|
1369 | }
|
1370 | };
|
1371 |
|
1372 | function getActiveIndexByTranslate(swiper) {
|
1373 | const {
|
1374 | slidesGrid,
|
1375 | params
|
1376 | } = swiper;
|
1377 | const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
1378 | let activeIndex;
|
1379 | for (let i = 0; i < slidesGrid.length; i += 1) {
|
1380 | if (typeof slidesGrid[i + 1] !== 'undefined') {
|
1381 | if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) {
|
1382 | activeIndex = i;
|
1383 | } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
|
1384 | activeIndex = i + 1;
|
1385 | }
|
1386 | } else if (translate >= slidesGrid[i]) {
|
1387 | activeIndex = i;
|
1388 | }
|
1389 | }
|
1390 |
|
1391 | if (params.normalizeSlideIndex) {
|
1392 | if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
|
1393 | }
|
1394 | return activeIndex;
|
1395 | }
|
1396 | function updateActiveIndex(newActiveIndex) {
|
1397 | const swiper = this;
|
1398 | const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
1399 | const {
|
1400 | snapGrid,
|
1401 | params,
|
1402 | activeIndex: previousIndex,
|
1403 | realIndex: previousRealIndex,
|
1404 | snapIndex: previousSnapIndex
|
1405 | } = swiper;
|
1406 | let activeIndex = newActiveIndex;
|
1407 | let snapIndex;
|
1408 | const getVirtualRealIndex = aIndex => {
|
1409 | let realIndex = aIndex - swiper.virtual.slidesBefore;
|
1410 | if (realIndex < 0) {
|
1411 | realIndex = swiper.virtual.slides.length + realIndex;
|
1412 | }
|
1413 | if (realIndex >= swiper.virtual.slides.length) {
|
1414 | realIndex -= swiper.virtual.slides.length;
|
1415 | }
|
1416 | return realIndex;
|
1417 | };
|
1418 | if (typeof activeIndex === 'undefined') {
|
1419 | activeIndex = getActiveIndexByTranslate(swiper);
|
1420 | }
|
1421 | if (snapGrid.indexOf(translate) >= 0) {
|
1422 | snapIndex = snapGrid.indexOf(translate);
|
1423 | } else {
|
1424 | const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
|
1425 | snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
|
1426 | }
|
1427 | if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
|
1428 | if (activeIndex === previousIndex && !swiper.params.loop) {
|
1429 | if (snapIndex !== previousSnapIndex) {
|
1430 | swiper.snapIndex = snapIndex;
|
1431 | swiper.emit('snapIndexChange');
|
1432 | }
|
1433 | return;
|
1434 | }
|
1435 | if (activeIndex === previousIndex && swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
|
1436 | swiper.realIndex = getVirtualRealIndex(activeIndex);
|
1437 | return;
|
1438 | }
|
1439 | const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
1440 |
|
1441 |
|
1442 | let realIndex;
|
1443 | if (swiper.virtual && params.virtual.enabled && params.loop) {
|
1444 | realIndex = getVirtualRealIndex(activeIndex);
|
1445 | } else if (gridEnabled) {
|
1446 | const firstSlideInColumn = swiper.slides.filter(slideEl => slideEl.column === activeIndex)[0];
|
1447 | let activeSlideIndex = parseInt(firstSlideInColumn.getAttribute('data-swiper-slide-index'), 10);
|
1448 | if (Number.isNaN(activeSlideIndex)) {
|
1449 | activeSlideIndex = Math.max(swiper.slides.indexOf(firstSlideInColumn), 0);
|
1450 | }
|
1451 | realIndex = Math.floor(activeSlideIndex / params.grid.rows);
|
1452 | } else if (swiper.slides[activeIndex]) {
|
1453 | const slideIndex = swiper.slides[activeIndex].getAttribute('data-swiper-slide-index');
|
1454 | if (slideIndex) {
|
1455 | realIndex = parseInt(slideIndex, 10);
|
1456 | } else {
|
1457 | realIndex = activeIndex;
|
1458 | }
|
1459 | } else {
|
1460 | realIndex = activeIndex;
|
1461 | }
|
1462 | Object.assign(swiper, {
|
1463 | previousSnapIndex,
|
1464 | snapIndex,
|
1465 | previousRealIndex,
|
1466 | realIndex,
|
1467 | previousIndex,
|
1468 | activeIndex
|
1469 | });
|
1470 | if (swiper.initialized) {
|
1471 | preload(swiper);
|
1472 | }
|
1473 | swiper.emit('activeIndexChange');
|
1474 | swiper.emit('snapIndexChange');
|
1475 | if (swiper.initialized || swiper.params.runCallbacksOnInit) {
|
1476 | if (previousRealIndex !== realIndex) {
|
1477 | swiper.emit('realIndexChange');
|
1478 | }
|
1479 | swiper.emit('slideChange');
|
1480 | }
|
1481 | }
|
1482 |
|
1483 | function updateClickedSlide(el, path) {
|
1484 | const swiper = this;
|
1485 | const params = swiper.params;
|
1486 | let slide = el.closest(`.${params.slideClass}, swiper-slide`);
|
1487 | if (!slide && swiper.isElement && path && path.length > 1 && path.includes(el)) {
|
1488 | [...path.slice(path.indexOf(el) + 1, path.length)].forEach(pathEl => {
|
1489 | if (!slide && pathEl.matches && pathEl.matches(`.${params.slideClass}, swiper-slide`)) {
|
1490 | slide = pathEl;
|
1491 | }
|
1492 | });
|
1493 | }
|
1494 | let slideFound = false;
|
1495 | let slideIndex;
|
1496 | if (slide) {
|
1497 | for (let i = 0; i < swiper.slides.length; i += 1) {
|
1498 | if (swiper.slides[i] === slide) {
|
1499 | slideFound = true;
|
1500 | slideIndex = i;
|
1501 | break;
|
1502 | }
|
1503 | }
|
1504 | }
|
1505 | if (slide && slideFound) {
|
1506 | swiper.clickedSlide = slide;
|
1507 | if (swiper.virtual && swiper.params.virtual.enabled) {
|
1508 | swiper.clickedIndex = parseInt(slide.getAttribute('data-swiper-slide-index'), 10);
|
1509 | } else {
|
1510 | swiper.clickedIndex = slideIndex;
|
1511 | }
|
1512 | } else {
|
1513 | swiper.clickedSlide = undefined;
|
1514 | swiper.clickedIndex = undefined;
|
1515 | return;
|
1516 | }
|
1517 | if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
|
1518 | swiper.slideToClickedSlide();
|
1519 | }
|
1520 | }
|
1521 |
|
1522 | var update = {
|
1523 | updateSize,
|
1524 | updateSlides,
|
1525 | updateAutoHeight,
|
1526 | updateSlidesOffset,
|
1527 | updateSlidesProgress,
|
1528 | updateProgress,
|
1529 | updateSlidesClasses,
|
1530 | updateActiveIndex,
|
1531 | updateClickedSlide
|
1532 | };
|
1533 |
|
1534 | function getSwiperTranslate(axis) {
|
1535 | if (axis === void 0) {
|
1536 | axis = this.isHorizontal() ? 'x' : 'y';
|
1537 | }
|
1538 | const swiper = this;
|
1539 | const {
|
1540 | params,
|
1541 | rtlTranslate: rtl,
|
1542 | translate,
|
1543 | wrapperEl
|
1544 | } = swiper;
|
1545 | if (params.virtualTranslate) {
|
1546 | return rtl ? -translate : translate;
|
1547 | }
|
1548 | if (params.cssMode) {
|
1549 | return translate;
|
1550 | }
|
1551 | let currentTranslate = getTranslate(wrapperEl, axis);
|
1552 | currentTranslate += swiper.cssOverflowAdjustment();
|
1553 | if (rtl) currentTranslate = -currentTranslate;
|
1554 | return currentTranslate || 0;
|
1555 | }
|
1556 |
|
1557 | function setTranslate(translate, byController) {
|
1558 | const swiper = this;
|
1559 | const {
|
1560 | rtlTranslate: rtl,
|
1561 | params,
|
1562 | wrapperEl,
|
1563 | progress
|
1564 | } = swiper;
|
1565 | let x = 0;
|
1566 | let y = 0;
|
1567 | const z = 0;
|
1568 | if (swiper.isHorizontal()) {
|
1569 | x = rtl ? -translate : translate;
|
1570 | } else {
|
1571 | y = translate;
|
1572 | }
|
1573 | if (params.roundLengths) {
|
1574 | x = Math.floor(x);
|
1575 | y = Math.floor(y);
|
1576 | }
|
1577 | swiper.previousTranslate = swiper.translate;
|
1578 | swiper.translate = swiper.isHorizontal() ? x : y;
|
1579 | if (params.cssMode) {
|
1580 | wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
|
1581 | } else if (!params.virtualTranslate) {
|
1582 | if (swiper.isHorizontal()) {
|
1583 | x -= swiper.cssOverflowAdjustment();
|
1584 | } else {
|
1585 | y -= swiper.cssOverflowAdjustment();
|
1586 | }
|
1587 | wrapperEl.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
|
1588 | }
|
1589 |
|
1590 |
|
1591 | let newProgress;
|
1592 | const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
1593 | if (translatesDiff === 0) {
|
1594 | newProgress = 0;
|
1595 | } else {
|
1596 | newProgress = (translate - swiper.minTranslate()) / translatesDiff;
|
1597 | }
|
1598 | if (newProgress !== progress) {
|
1599 | swiper.updateProgress(translate);
|
1600 | }
|
1601 | swiper.emit('setTranslate', swiper.translate, byController);
|
1602 | }
|
1603 |
|
1604 | function minTranslate() {
|
1605 | return -this.snapGrid[0];
|
1606 | }
|
1607 |
|
1608 | function maxTranslate() {
|
1609 | return -this.snapGrid[this.snapGrid.length - 1];
|
1610 | }
|
1611 |
|
1612 | function translateTo(translate, speed, runCallbacks, translateBounds, internal) {
|
1613 | if (translate === void 0) {
|
1614 | translate = 0;
|
1615 | }
|
1616 | if (speed === void 0) {
|
1617 | speed = this.params.speed;
|
1618 | }
|
1619 | if (runCallbacks === void 0) {
|
1620 | runCallbacks = true;
|
1621 | }
|
1622 | if (translateBounds === void 0) {
|
1623 | translateBounds = true;
|
1624 | }
|
1625 | const swiper = this;
|
1626 | const {
|
1627 | params,
|
1628 | wrapperEl
|
1629 | } = swiper;
|
1630 | if (swiper.animating && params.preventInteractionOnTransition) {
|
1631 | return false;
|
1632 | }
|
1633 | const minTranslate = swiper.minTranslate();
|
1634 | const maxTranslate = swiper.maxTranslate();
|
1635 | let newTranslate;
|
1636 | if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate;
|
1637 |
|
1638 |
|
1639 | swiper.updateProgress(newTranslate);
|
1640 | if (params.cssMode) {
|
1641 | const isH = swiper.isHorizontal();
|
1642 | if (speed === 0) {
|
1643 | wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
|
1644 | } else {
|
1645 | if (!swiper.support.smoothScroll) {
|
1646 | animateCSSModeScroll({
|
1647 | swiper,
|
1648 | targetPosition: -newTranslate,
|
1649 | side: isH ? 'left' : 'top'
|
1650 | });
|
1651 | return true;
|
1652 | }
|
1653 | wrapperEl.scrollTo({
|
1654 | [isH ? 'left' : 'top']: -newTranslate,
|
1655 | behavior: 'smooth'
|
1656 | });
|
1657 | }
|
1658 | return true;
|
1659 | }
|
1660 | if (speed === 0) {
|
1661 | swiper.setTransition(0);
|
1662 | swiper.setTranslate(newTranslate);
|
1663 | if (runCallbacks) {
|
1664 | swiper.emit('beforeTransitionStart', speed, internal);
|
1665 | swiper.emit('transitionEnd');
|
1666 | }
|
1667 | } else {
|
1668 | swiper.setTransition(speed);
|
1669 | swiper.setTranslate(newTranslate);
|
1670 | if (runCallbacks) {
|
1671 | swiper.emit('beforeTransitionStart', speed, internal);
|
1672 | swiper.emit('transitionStart');
|
1673 | }
|
1674 | if (!swiper.animating) {
|
1675 | swiper.animating = true;
|
1676 | if (!swiper.onTranslateToWrapperTransitionEnd) {
|
1677 | swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
|
1678 | if (!swiper || swiper.destroyed) return;
|
1679 | if (e.target !== this) return;
|
1680 | swiper.wrapperEl.removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
|
1681 | swiper.onTranslateToWrapperTransitionEnd = null;
|
1682 | delete swiper.onTranslateToWrapperTransitionEnd;
|
1683 | swiper.animating = false;
|
1684 | if (runCallbacks) {
|
1685 | swiper.emit('transitionEnd');
|
1686 | }
|
1687 | };
|
1688 | }
|
1689 | swiper.wrapperEl.addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
|
1690 | }
|
1691 | }
|
1692 | return true;
|
1693 | }
|
1694 |
|
1695 | var translate = {
|
1696 | getTranslate: getSwiperTranslate,
|
1697 | setTranslate,
|
1698 | minTranslate,
|
1699 | maxTranslate,
|
1700 | translateTo
|
1701 | };
|
1702 |
|
1703 | function setTransition(duration, byController) {
|
1704 | const swiper = this;
|
1705 | if (!swiper.params.cssMode) {
|
1706 | swiper.wrapperEl.style.transitionDuration = `${duration}ms`;
|
1707 | swiper.wrapperEl.style.transitionDelay = duration === 0 ? `0ms` : '';
|
1708 | }
|
1709 | swiper.emit('setTransition', duration, byController);
|
1710 | }
|
1711 |
|
1712 | function transitionEmit(_ref) {
|
1713 | let {
|
1714 | swiper,
|
1715 | runCallbacks,
|
1716 | direction,
|
1717 | step
|
1718 | } = _ref;
|
1719 | const {
|
1720 | activeIndex,
|
1721 | previousIndex
|
1722 | } = swiper;
|
1723 | let dir = direction;
|
1724 | if (!dir) {
|
1725 | if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset';
|
1726 | }
|
1727 | swiper.emit(`transition${step}`);
|
1728 | if (runCallbacks && activeIndex !== previousIndex) {
|
1729 | if (dir === 'reset') {
|
1730 | swiper.emit(`slideResetTransition${step}`);
|
1731 | return;
|
1732 | }
|
1733 | swiper.emit(`slideChangeTransition${step}`);
|
1734 | if (dir === 'next') {
|
1735 | swiper.emit(`slideNextTransition${step}`);
|
1736 | } else {
|
1737 | swiper.emit(`slidePrevTransition${step}`);
|
1738 | }
|
1739 | }
|
1740 | }
|
1741 |
|
1742 | function transitionStart(runCallbacks, direction) {
|
1743 | if (runCallbacks === void 0) {
|
1744 | runCallbacks = true;
|
1745 | }
|
1746 | const swiper = this;
|
1747 | const {
|
1748 | params
|
1749 | } = swiper;
|
1750 | if (params.cssMode) return;
|
1751 | if (params.autoHeight) {
|
1752 | swiper.updateAutoHeight();
|
1753 | }
|
1754 | transitionEmit({
|
1755 | swiper,
|
1756 | runCallbacks,
|
1757 | direction,
|
1758 | step: 'Start'
|
1759 | });
|
1760 | }
|
1761 |
|
1762 | function transitionEnd(runCallbacks, direction) {
|
1763 | if (runCallbacks === void 0) {
|
1764 | runCallbacks = true;
|
1765 | }
|
1766 | const swiper = this;
|
1767 | const {
|
1768 | params
|
1769 | } = swiper;
|
1770 | swiper.animating = false;
|
1771 | if (params.cssMode) return;
|
1772 | swiper.setTransition(0);
|
1773 | transitionEmit({
|
1774 | swiper,
|
1775 | runCallbacks,
|
1776 | direction,
|
1777 | step: 'End'
|
1778 | });
|
1779 | }
|
1780 |
|
1781 | var transition = {
|
1782 | setTransition,
|
1783 | transitionStart,
|
1784 | transitionEnd
|
1785 | };
|
1786 |
|
1787 | function slideTo(index, speed, runCallbacks, internal, initial) {
|
1788 | if (index === void 0) {
|
1789 | index = 0;
|
1790 | }
|
1791 | if (runCallbacks === void 0) {
|
1792 | runCallbacks = true;
|
1793 | }
|
1794 | if (typeof index === 'string') {
|
1795 | index = parseInt(index, 10);
|
1796 | }
|
1797 | const swiper = this;
|
1798 | let slideIndex = index;
|
1799 | if (slideIndex < 0) slideIndex = 0;
|
1800 | const {
|
1801 | params,
|
1802 | snapGrid,
|
1803 | slidesGrid,
|
1804 | previousIndex,
|
1805 | activeIndex,
|
1806 | rtlTranslate: rtl,
|
1807 | wrapperEl,
|
1808 | enabled
|
1809 | } = swiper;
|
1810 | if (!enabled && !internal && !initial || swiper.destroyed || swiper.animating && params.preventInteractionOnTransition) {
|
1811 | return false;
|
1812 | }
|
1813 | if (typeof speed === 'undefined') {
|
1814 | speed = swiper.params.speed;
|
1815 | }
|
1816 | const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
|
1817 | let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
|
1818 | if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
|
1819 | const translate = -snapGrid[snapIndex];
|
1820 |
|
1821 | if (params.normalizeSlideIndex) {
|
1822 | for (let i = 0; i < slidesGrid.length; i += 1) {
|
1823 | const normalizedTranslate = -Math.floor(translate * 100);
|
1824 | const normalizedGrid = Math.floor(slidesGrid[i] * 100);
|
1825 | const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100);
|
1826 | if (typeof slidesGrid[i + 1] !== 'undefined') {
|
1827 | if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) {
|
1828 | slideIndex = i;
|
1829 | } else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) {
|
1830 | slideIndex = i + 1;
|
1831 | }
|
1832 | } else if (normalizedTranslate >= normalizedGrid) {
|
1833 | slideIndex = i;
|
1834 | }
|
1835 | }
|
1836 | }
|
1837 |
|
1838 | if (swiper.initialized && slideIndex !== activeIndex) {
|
1839 | if (!swiper.allowSlideNext && (rtl ? translate > swiper.translate && translate > swiper.minTranslate() : translate < swiper.translate && translate < swiper.minTranslate())) {
|
1840 | return false;
|
1841 | }
|
1842 | if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
|
1843 | if ((activeIndex || 0) !== slideIndex) {
|
1844 | return false;
|
1845 | }
|
1846 | }
|
1847 | }
|
1848 | if (slideIndex !== (previousIndex || 0) && runCallbacks) {
|
1849 | swiper.emit('beforeSlideChangeStart');
|
1850 | }
|
1851 |
|
1852 |
|
1853 | swiper.updateProgress(translate);
|
1854 | let direction;
|
1855 | if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset';
|
1856 |
|
1857 |
|
1858 | if (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate) {
|
1859 | swiper.updateActiveIndex(slideIndex);
|
1860 |
|
1861 | if (params.autoHeight) {
|
1862 | swiper.updateAutoHeight();
|
1863 | }
|
1864 | swiper.updateSlidesClasses();
|
1865 | if (params.effect !== 'slide') {
|
1866 | swiper.setTranslate(translate);
|
1867 | }
|
1868 | if (direction !== 'reset') {
|
1869 | swiper.transitionStart(runCallbacks, direction);
|
1870 | swiper.transitionEnd(runCallbacks, direction);
|
1871 | }
|
1872 | return false;
|
1873 | }
|
1874 | if (params.cssMode) {
|
1875 | const isH = swiper.isHorizontal();
|
1876 | const t = rtl ? translate : -translate;
|
1877 | if (speed === 0) {
|
1878 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
1879 | if (isVirtual) {
|
1880 | swiper.wrapperEl.style.scrollSnapType = 'none';
|
1881 | swiper._immediateVirtual = true;
|
1882 | }
|
1883 | if (isVirtual && !swiper._cssModeVirtualInitialSet && swiper.params.initialSlide > 0) {
|
1884 | swiper._cssModeVirtualInitialSet = true;
|
1885 | requestAnimationFrame(() => {
|
1886 | wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
|
1887 | });
|
1888 | } else {
|
1889 | wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
|
1890 | }
|
1891 | if (isVirtual) {
|
1892 | requestAnimationFrame(() => {
|
1893 | swiper.wrapperEl.style.scrollSnapType = '';
|
1894 | swiper._immediateVirtual = false;
|
1895 | });
|
1896 | }
|
1897 | } else {
|
1898 | if (!swiper.support.smoothScroll) {
|
1899 | animateCSSModeScroll({
|
1900 | swiper,
|
1901 | targetPosition: t,
|
1902 | side: isH ? 'left' : 'top'
|
1903 | });
|
1904 | return true;
|
1905 | }
|
1906 | wrapperEl.scrollTo({
|
1907 | [isH ? 'left' : 'top']: t,
|
1908 | behavior: 'smooth'
|
1909 | });
|
1910 | }
|
1911 | return true;
|
1912 | }
|
1913 | swiper.setTransition(speed);
|
1914 | swiper.setTranslate(translate);
|
1915 | swiper.updateActiveIndex(slideIndex);
|
1916 | swiper.updateSlidesClasses();
|
1917 | swiper.emit('beforeTransitionStart', speed, internal);
|
1918 | swiper.transitionStart(runCallbacks, direction);
|
1919 | if (speed === 0) {
|
1920 | swiper.transitionEnd(runCallbacks, direction);
|
1921 | } else if (!swiper.animating) {
|
1922 | swiper.animating = true;
|
1923 | if (!swiper.onSlideToWrapperTransitionEnd) {
|
1924 | swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
|
1925 | if (!swiper || swiper.destroyed) return;
|
1926 | if (e.target !== this) return;
|
1927 | swiper.wrapperEl.removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
|
1928 | swiper.onSlideToWrapperTransitionEnd = null;
|
1929 | delete swiper.onSlideToWrapperTransitionEnd;
|
1930 | swiper.transitionEnd(runCallbacks, direction);
|
1931 | };
|
1932 | }
|
1933 | swiper.wrapperEl.addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
|
1934 | }
|
1935 | return true;
|
1936 | }
|
1937 |
|
1938 | function slideToLoop(index, speed, runCallbacks, internal) {
|
1939 | if (index === void 0) {
|
1940 | index = 0;
|
1941 | }
|
1942 | if (runCallbacks === void 0) {
|
1943 | runCallbacks = true;
|
1944 | }
|
1945 | if (typeof index === 'string') {
|
1946 | const indexAsNumber = parseInt(index, 10);
|
1947 | index = indexAsNumber;
|
1948 | }
|
1949 | const swiper = this;
|
1950 | if (swiper.destroyed) return;
|
1951 | if (typeof speed === 'undefined') {
|
1952 | speed = swiper.params.speed;
|
1953 | }
|
1954 | const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
|
1955 | let newIndex = index;
|
1956 | if (swiper.params.loop) {
|
1957 | if (swiper.virtual && swiper.params.virtual.enabled) {
|
1958 |
|
1959 | newIndex = newIndex + swiper.virtual.slidesBefore;
|
1960 | } else {
|
1961 | let targetSlideIndex;
|
1962 | if (gridEnabled) {
|
1963 | const slideIndex = newIndex * swiper.params.grid.rows;
|
1964 | targetSlideIndex = swiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex)[0].column;
|
1965 | } else {
|
1966 | targetSlideIndex = swiper.getSlideIndexByData(newIndex);
|
1967 | }
|
1968 | const cols = gridEnabled ? Math.ceil(swiper.slides.length / swiper.params.grid.rows) : swiper.slides.length;
|
1969 | const {
|
1970 | centeredSlides
|
1971 | } = swiper.params;
|
1972 | let slidesPerView = swiper.params.slidesPerView;
|
1973 | if (slidesPerView === 'auto') {
|
1974 | slidesPerView = swiper.slidesPerViewDynamic();
|
1975 | } else {
|
1976 | slidesPerView = Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
|
1977 | if (centeredSlides && slidesPerView % 2 === 0) {
|
1978 | slidesPerView = slidesPerView + 1;
|
1979 | }
|
1980 | }
|
1981 | let needLoopFix = cols - targetSlideIndex < slidesPerView;
|
1982 | if (centeredSlides) {
|
1983 | needLoopFix = needLoopFix || targetSlideIndex < Math.ceil(slidesPerView / 2);
|
1984 | }
|
1985 | if (internal && centeredSlides && swiper.params.slidesPerView !== 'auto' && !gridEnabled) {
|
1986 | needLoopFix = false;
|
1987 | }
|
1988 | if (needLoopFix) {
|
1989 | const direction = centeredSlides ? targetSlideIndex < swiper.activeIndex ? 'prev' : 'next' : targetSlideIndex - swiper.activeIndex - 1 < swiper.params.slidesPerView ? 'next' : 'prev';
|
1990 | swiper.loopFix({
|
1991 | direction,
|
1992 | slideTo: true,
|
1993 | activeSlideIndex: direction === 'next' ? targetSlideIndex + 1 : targetSlideIndex - cols + 1,
|
1994 | slideRealIndex: direction === 'next' ? swiper.realIndex : undefined
|
1995 | });
|
1996 | }
|
1997 | if (gridEnabled) {
|
1998 | const slideIndex = newIndex * swiper.params.grid.rows;
|
1999 | newIndex = swiper.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex)[0].column;
|
2000 | } else {
|
2001 | newIndex = swiper.getSlideIndexByData(newIndex);
|
2002 | }
|
2003 | }
|
2004 | }
|
2005 | requestAnimationFrame(() => {
|
2006 | swiper.slideTo(newIndex, speed, runCallbacks, internal);
|
2007 | });
|
2008 | return swiper;
|
2009 | }
|
2010 |
|
2011 |
|
2012 | function slideNext(speed, runCallbacks, internal) {
|
2013 | if (runCallbacks === void 0) {
|
2014 | runCallbacks = true;
|
2015 | }
|
2016 | const swiper = this;
|
2017 | const {
|
2018 | enabled,
|
2019 | params,
|
2020 | animating
|
2021 | } = swiper;
|
2022 | if (!enabled || swiper.destroyed) return swiper;
|
2023 | if (typeof speed === 'undefined') {
|
2024 | speed = swiper.params.speed;
|
2025 | }
|
2026 | let perGroup = params.slidesPerGroup;
|
2027 | if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
|
2028 | perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
|
2029 | }
|
2030 | const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
|
2031 | const isVirtual = swiper.virtual && params.virtual.enabled;
|
2032 | if (params.loop) {
|
2033 | if (animating && !isVirtual && params.loopPreventsSliding) return false;
|
2034 | swiper.loopFix({
|
2035 | direction: 'next'
|
2036 | });
|
2037 |
|
2038 | swiper._clientLeft = swiper.wrapperEl.clientLeft;
|
2039 | if (swiper.activeIndex === swiper.slides.length - 1 && params.cssMode) {
|
2040 | requestAnimationFrame(() => {
|
2041 | swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
|
2042 | });
|
2043 | return true;
|
2044 | }
|
2045 | }
|
2046 | if (params.rewind && swiper.isEnd) {
|
2047 | return swiper.slideTo(0, speed, runCallbacks, internal);
|
2048 | }
|
2049 | return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
|
2050 | }
|
2051 |
|
2052 |
|
2053 | function slidePrev(speed, runCallbacks, internal) {
|
2054 | if (runCallbacks === void 0) {
|
2055 | runCallbacks = true;
|
2056 | }
|
2057 | const swiper = this;
|
2058 | const {
|
2059 | params,
|
2060 | snapGrid,
|
2061 | slidesGrid,
|
2062 | rtlTranslate,
|
2063 | enabled,
|
2064 | animating
|
2065 | } = swiper;
|
2066 | if (!enabled || swiper.destroyed) return swiper;
|
2067 | if (typeof speed === 'undefined') {
|
2068 | speed = swiper.params.speed;
|
2069 | }
|
2070 | const isVirtual = swiper.virtual && params.virtual.enabled;
|
2071 | if (params.loop) {
|
2072 | if (animating && !isVirtual && params.loopPreventsSliding) return false;
|
2073 | swiper.loopFix({
|
2074 | direction: 'prev'
|
2075 | });
|
2076 |
|
2077 | swiper._clientLeft = swiper.wrapperEl.clientLeft;
|
2078 | }
|
2079 | const translate = rtlTranslate ? swiper.translate : -swiper.translate;
|
2080 | function normalize(val) {
|
2081 | if (val < 0) return -Math.floor(Math.abs(val));
|
2082 | return Math.floor(val);
|
2083 | }
|
2084 | const normalizedTranslate = normalize(translate);
|
2085 | const normalizedSnapGrid = snapGrid.map(val => normalize(val));
|
2086 | let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
|
2087 | if (typeof prevSnap === 'undefined' && params.cssMode) {
|
2088 | let prevSnapIndex;
|
2089 | snapGrid.forEach((snap, snapIndex) => {
|
2090 | if (normalizedTranslate >= snap) {
|
2091 |
|
2092 | prevSnapIndex = snapIndex;
|
2093 | }
|
2094 | });
|
2095 | if (typeof prevSnapIndex !== 'undefined') {
|
2096 | prevSnap = snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
|
2097 | }
|
2098 | }
|
2099 | let prevIndex = 0;
|
2100 | if (typeof prevSnap !== 'undefined') {
|
2101 | prevIndex = slidesGrid.indexOf(prevSnap);
|
2102 | if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
|
2103 | if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
|
2104 | prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
|
2105 | prevIndex = Math.max(prevIndex, 0);
|
2106 | }
|
2107 | }
|
2108 | if (params.rewind && swiper.isBeginning) {
|
2109 | const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
|
2110 | return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
|
2111 | } else if (params.loop && swiper.activeIndex === 0 && params.cssMode) {
|
2112 | requestAnimationFrame(() => {
|
2113 | swiper.slideTo(prevIndex, speed, runCallbacks, internal);
|
2114 | });
|
2115 | return true;
|
2116 | }
|
2117 | return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
|
2118 | }
|
2119 |
|
2120 |
|
2121 | function slideReset(speed, runCallbacks, internal) {
|
2122 | if (runCallbacks === void 0) {
|
2123 | runCallbacks = true;
|
2124 | }
|
2125 | const swiper = this;
|
2126 | if (swiper.destroyed) return;
|
2127 | if (typeof speed === 'undefined') {
|
2128 | speed = swiper.params.speed;
|
2129 | }
|
2130 | return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
|
2131 | }
|
2132 |
|
2133 |
|
2134 | function slideToClosest(speed, runCallbacks, internal, threshold) {
|
2135 | if (runCallbacks === void 0) {
|
2136 | runCallbacks = true;
|
2137 | }
|
2138 | if (threshold === void 0) {
|
2139 | threshold = 0.5;
|
2140 | }
|
2141 | const swiper = this;
|
2142 | if (swiper.destroyed) return;
|
2143 | if (typeof speed === 'undefined') {
|
2144 | speed = swiper.params.speed;
|
2145 | }
|
2146 | let index = swiper.activeIndex;
|
2147 | const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
|
2148 | const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
|
2149 | const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
2150 | if (translate >= swiper.snapGrid[snapIndex]) {
|
2151 |
|
2152 |
|
2153 | const currentSnap = swiper.snapGrid[snapIndex];
|
2154 | const nextSnap = swiper.snapGrid[snapIndex + 1];
|
2155 | if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
|
2156 | index += swiper.params.slidesPerGroup;
|
2157 | }
|
2158 | } else {
|
2159 |
|
2160 |
|
2161 | const prevSnap = swiper.snapGrid[snapIndex - 1];
|
2162 | const currentSnap = swiper.snapGrid[snapIndex];
|
2163 | if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
|
2164 | index -= swiper.params.slidesPerGroup;
|
2165 | }
|
2166 | }
|
2167 | index = Math.max(index, 0);
|
2168 | index = Math.min(index, swiper.slidesGrid.length - 1);
|
2169 | return swiper.slideTo(index, speed, runCallbacks, internal);
|
2170 | }
|
2171 |
|
2172 | function slideToClickedSlide() {
|
2173 | const swiper = this;
|
2174 | if (swiper.destroyed) return;
|
2175 | const {
|
2176 | params,
|
2177 | slidesEl
|
2178 | } = swiper;
|
2179 | const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
|
2180 | let slideToIndex = swiper.clickedIndex;
|
2181 | let realIndex;
|
2182 | const slideSelector = swiper.isElement ? `swiper-slide` : `.${params.slideClass}`;
|
2183 | if (params.loop) {
|
2184 | if (swiper.animating) return;
|
2185 | realIndex = parseInt(swiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10);
|
2186 | if (params.centeredSlides) {
|
2187 | if (slideToIndex < swiper.loopedSlides - slidesPerView / 2 || slideToIndex > swiper.slides.length - swiper.loopedSlides + slidesPerView / 2) {
|
2188 | swiper.loopFix();
|
2189 | slideToIndex = swiper.getSlideIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
|
2190 | nextTick(() => {
|
2191 | swiper.slideTo(slideToIndex);
|
2192 | });
|
2193 | } else {
|
2194 | swiper.slideTo(slideToIndex);
|
2195 | }
|
2196 | } else if (slideToIndex > swiper.slides.length - slidesPerView) {
|
2197 | swiper.loopFix();
|
2198 | slideToIndex = swiper.getSlideIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
|
2199 | nextTick(() => {
|
2200 | swiper.slideTo(slideToIndex);
|
2201 | });
|
2202 | } else {
|
2203 | swiper.slideTo(slideToIndex);
|
2204 | }
|
2205 | } else {
|
2206 | swiper.slideTo(slideToIndex);
|
2207 | }
|
2208 | }
|
2209 |
|
2210 | var slide = {
|
2211 | slideTo,
|
2212 | slideToLoop,
|
2213 | slideNext,
|
2214 | slidePrev,
|
2215 | slideReset,
|
2216 | slideToClosest,
|
2217 | slideToClickedSlide
|
2218 | };
|
2219 |
|
2220 | function loopCreate(slideRealIndex) {
|
2221 | const swiper = this;
|
2222 | const {
|
2223 | params,
|
2224 | slidesEl
|
2225 | } = swiper;
|
2226 | if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
|
2227 | const initSlides = () => {
|
2228 | const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
|
2229 | slides.forEach((el, index) => {
|
2230 | el.setAttribute('data-swiper-slide-index', index);
|
2231 | });
|
2232 | };
|
2233 | const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
2234 | const slidesPerGroup = params.slidesPerGroup * (gridEnabled ? params.grid.rows : 1);
|
2235 | const shouldFillGroup = swiper.slides.length % slidesPerGroup !== 0;
|
2236 | const shouldFillGrid = gridEnabled && swiper.slides.length % params.grid.rows !== 0;
|
2237 | const addBlankSlides = amountOfSlides => {
|
2238 | for (let i = 0; i < amountOfSlides; i += 1) {
|
2239 | const slideEl = swiper.isElement ? createElement('swiper-slide', [params.slideBlankClass]) : createElement('div', [params.slideClass, params.slideBlankClass]);
|
2240 | swiper.slidesEl.append(slideEl);
|
2241 | }
|
2242 | };
|
2243 | if (shouldFillGroup) {
|
2244 | if (params.loopAddBlankSlides) {
|
2245 | const slidesToAdd = slidesPerGroup - swiper.slides.length % slidesPerGroup;
|
2246 | addBlankSlides(slidesToAdd);
|
2247 | swiper.recalcSlides();
|
2248 | swiper.updateSlides();
|
2249 | } else {
|
2250 | showWarning('Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
|
2251 | }
|
2252 | initSlides();
|
2253 | } else if (shouldFillGrid) {
|
2254 | if (params.loopAddBlankSlides) {
|
2255 | const slidesToAdd = params.grid.rows - swiper.slides.length % params.grid.rows;
|
2256 | addBlankSlides(slidesToAdd);
|
2257 | swiper.recalcSlides();
|
2258 | swiper.updateSlides();
|
2259 | } else {
|
2260 | showWarning('Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
|
2261 | }
|
2262 | initSlides();
|
2263 | } else {
|
2264 | initSlides();
|
2265 | }
|
2266 | swiper.loopFix({
|
2267 | slideRealIndex,
|
2268 | direction: params.centeredSlides ? undefined : 'next'
|
2269 | });
|
2270 | }
|
2271 |
|
2272 | function loopFix(_temp) {
|
2273 | let {
|
2274 | slideRealIndex,
|
2275 | slideTo = true,
|
2276 | direction,
|
2277 | setTranslate,
|
2278 | activeSlideIndex,
|
2279 | byController,
|
2280 | byMousewheel
|
2281 | } = _temp === void 0 ? {} : _temp;
|
2282 | const swiper = this;
|
2283 | if (!swiper.params.loop) return;
|
2284 | swiper.emit('beforeLoopFix');
|
2285 | const {
|
2286 | slides,
|
2287 | allowSlidePrev,
|
2288 | allowSlideNext,
|
2289 | slidesEl,
|
2290 | params
|
2291 | } = swiper;
|
2292 | const {
|
2293 | centeredSlides
|
2294 | } = params;
|
2295 | swiper.allowSlidePrev = true;
|
2296 | swiper.allowSlideNext = true;
|
2297 | if (swiper.virtual && params.virtual.enabled) {
|
2298 | if (slideTo) {
|
2299 | if (!params.centeredSlides && swiper.snapIndex === 0) {
|
2300 | swiper.slideTo(swiper.virtual.slides.length, 0, false, true);
|
2301 | } else if (params.centeredSlides && swiper.snapIndex < params.slidesPerView) {
|
2302 | swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true);
|
2303 | } else if (swiper.snapIndex === swiper.snapGrid.length - 1) {
|
2304 | swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true);
|
2305 | }
|
2306 | }
|
2307 | swiper.allowSlidePrev = allowSlidePrev;
|
2308 | swiper.allowSlideNext = allowSlideNext;
|
2309 | swiper.emit('loopFix');
|
2310 | return;
|
2311 | }
|
2312 | let slidesPerView = params.slidesPerView;
|
2313 | if (slidesPerView === 'auto') {
|
2314 | slidesPerView = swiper.slidesPerViewDynamic();
|
2315 | } else {
|
2316 | slidesPerView = Math.ceil(parseFloat(params.slidesPerView, 10));
|
2317 | if (centeredSlides && slidesPerView % 2 === 0) {
|
2318 | slidesPerView = slidesPerView + 1;
|
2319 | }
|
2320 | }
|
2321 | const slidesPerGroup = params.slidesPerGroupAuto ? slidesPerView : params.slidesPerGroup;
|
2322 | let loopedSlides = slidesPerGroup;
|
2323 | if (loopedSlides % slidesPerGroup !== 0) {
|
2324 | loopedSlides += slidesPerGroup - loopedSlides % slidesPerGroup;
|
2325 | }
|
2326 | loopedSlides += params.loopAdditionalSlides;
|
2327 | swiper.loopedSlides = loopedSlides;
|
2328 | const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
2329 | if (slides.length < slidesPerView + loopedSlides) {
|
2330 | showWarning('Swiper Loop Warning: The number of slides is not enough for loop mode, it will be disabled and not function properly. You need to add more slides (or make duplicates) or lower the values of slidesPerView and slidesPerGroup parameters');
|
2331 | } else if (gridEnabled && params.grid.fill === 'row') {
|
2332 | showWarning('Swiper Loop Warning: Loop mode is not compatible with grid.fill = `row`');
|
2333 | }
|
2334 | const prependSlidesIndexes = [];
|
2335 | const appendSlidesIndexes = [];
|
2336 | let activeIndex = swiper.activeIndex;
|
2337 | if (typeof activeSlideIndex === 'undefined') {
|
2338 | activeSlideIndex = swiper.getSlideIndex(slides.filter(el => el.classList.contains(params.slideActiveClass))[0]);
|
2339 | } else {
|
2340 | activeIndex = activeSlideIndex;
|
2341 | }
|
2342 | const isNext = direction === 'next' || !direction;
|
2343 | const isPrev = direction === 'prev' || !direction;
|
2344 | let slidesPrepended = 0;
|
2345 | let slidesAppended = 0;
|
2346 | const cols = gridEnabled ? Math.ceil(slides.length / params.grid.rows) : slides.length;
|
2347 | const activeColIndex = gridEnabled ? slides[activeSlideIndex].column : activeSlideIndex;
|
2348 | const activeColIndexWithShift = activeColIndex + (centeredSlides && typeof setTranslate === 'undefined' ? -slidesPerView / 2 + 0.5 : 0);
|
2349 |
|
2350 | if (activeColIndexWithShift < loopedSlides) {
|
2351 | slidesPrepended = Math.max(loopedSlides - activeColIndexWithShift, slidesPerGroup);
|
2352 | for (let i = 0; i < loopedSlides - activeColIndexWithShift; i += 1) {
|
2353 | const index = i - Math.floor(i / cols) * cols;
|
2354 | if (gridEnabled) {
|
2355 | const colIndexToPrepend = cols - index - 1;
|
2356 | for (let i = slides.length - 1; i >= 0; i -= 1) {
|
2357 | if (slides[i].column === colIndexToPrepend) prependSlidesIndexes.push(i);
|
2358 | }
|
2359 |
|
2360 |
|
2361 |
|
2362 | } else {
|
2363 | prependSlidesIndexes.push(cols - index - 1);
|
2364 | }
|
2365 | }
|
2366 | } else if (activeColIndexWithShift + slidesPerView > cols - loopedSlides) {
|
2367 | slidesAppended = Math.max(activeColIndexWithShift - (cols - loopedSlides * 2), slidesPerGroup);
|
2368 | for (let i = 0; i < slidesAppended; i += 1) {
|
2369 | const index = i - Math.floor(i / cols) * cols;
|
2370 | if (gridEnabled) {
|
2371 | slides.forEach((slide, slideIndex) => {
|
2372 | if (slide.column === index) appendSlidesIndexes.push(slideIndex);
|
2373 | });
|
2374 | } else {
|
2375 | appendSlidesIndexes.push(index);
|
2376 | }
|
2377 | }
|
2378 | }
|
2379 | swiper.__preventObserver__ = true;
|
2380 | requestAnimationFrame(() => {
|
2381 | swiper.__preventObserver__ = false;
|
2382 | });
|
2383 | if (isPrev) {
|
2384 | prependSlidesIndexes.forEach(index => {
|
2385 | slides[index].swiperLoopMoveDOM = true;
|
2386 | slidesEl.prepend(slides[index]);
|
2387 | slides[index].swiperLoopMoveDOM = false;
|
2388 | });
|
2389 | }
|
2390 | if (isNext) {
|
2391 | appendSlidesIndexes.forEach(index => {
|
2392 | slides[index].swiperLoopMoveDOM = true;
|
2393 | slidesEl.append(slides[index]);
|
2394 | slides[index].swiperLoopMoveDOM = false;
|
2395 | });
|
2396 | }
|
2397 | swiper.recalcSlides();
|
2398 | if (params.slidesPerView === 'auto') {
|
2399 | swiper.updateSlides();
|
2400 | } else if (gridEnabled && (prependSlidesIndexes.length > 0 && isPrev || appendSlidesIndexes.length > 0 && isNext)) {
|
2401 | swiper.slides.forEach((slide, slideIndex) => {
|
2402 | swiper.grid.updateSlide(slideIndex, slide, swiper.slides);
|
2403 | });
|
2404 | }
|
2405 | if (params.watchSlidesProgress) {
|
2406 | swiper.updateSlidesOffset();
|
2407 | }
|
2408 | if (slideTo) {
|
2409 | if (prependSlidesIndexes.length > 0 && isPrev) {
|
2410 | if (typeof slideRealIndex === 'undefined') {
|
2411 | const currentSlideTranslate = swiper.slidesGrid[activeIndex];
|
2412 | const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended];
|
2413 | const diff = newSlideTranslate - currentSlideTranslate;
|
2414 | if (byMousewheel) {
|
2415 | swiper.setTranslate(swiper.translate - diff);
|
2416 | } else {
|
2417 | swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
|
2418 | if (setTranslate) {
|
2419 | swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
|
2420 | swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
|
2421 | }
|
2422 | }
|
2423 | } else {
|
2424 | if (setTranslate) {
|
2425 | const shift = gridEnabled ? prependSlidesIndexes.length / params.grid.rows : prependSlidesIndexes.length;
|
2426 | swiper.slideTo(swiper.activeIndex + shift, 0, false, true);
|
2427 | swiper.touchEventsData.currentTranslate = swiper.translate;
|
2428 | }
|
2429 | }
|
2430 | } else if (appendSlidesIndexes.length > 0 && isNext) {
|
2431 | if (typeof slideRealIndex === 'undefined') {
|
2432 | const currentSlideTranslate = swiper.slidesGrid[activeIndex];
|
2433 | const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended];
|
2434 | const diff = newSlideTranslate - currentSlideTranslate;
|
2435 | if (byMousewheel) {
|
2436 | swiper.setTranslate(swiper.translate - diff);
|
2437 | } else {
|
2438 | swiper.slideTo(activeIndex - slidesAppended, 0, false, true);
|
2439 | if (setTranslate) {
|
2440 | swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
|
2441 | swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
|
2442 | }
|
2443 | }
|
2444 | } else {
|
2445 | const shift = gridEnabled ? appendSlidesIndexes.length / params.grid.rows : appendSlidesIndexes.length;
|
2446 | swiper.slideTo(swiper.activeIndex - shift, 0, false, true);
|
2447 | }
|
2448 | }
|
2449 | }
|
2450 | swiper.allowSlidePrev = allowSlidePrev;
|
2451 | swiper.allowSlideNext = allowSlideNext;
|
2452 | if (swiper.controller && swiper.controller.control && !byController) {
|
2453 | const loopParams = {
|
2454 | slideRealIndex,
|
2455 | direction,
|
2456 | setTranslate,
|
2457 | activeSlideIndex,
|
2458 | byController: true
|
2459 | };
|
2460 | if (Array.isArray(swiper.controller.control)) {
|
2461 | swiper.controller.control.forEach(c => {
|
2462 | if (!c.destroyed && c.params.loop) c.loopFix({
|
2463 | ...loopParams,
|
2464 | slideTo: c.params.slidesPerView === params.slidesPerView ? slideTo : false
|
2465 | });
|
2466 | });
|
2467 | } else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) {
|
2468 | swiper.controller.control.loopFix({
|
2469 | ...loopParams,
|
2470 | slideTo: swiper.controller.control.params.slidesPerView === params.slidesPerView ? slideTo : false
|
2471 | });
|
2472 | }
|
2473 | }
|
2474 | swiper.emit('loopFix');
|
2475 | }
|
2476 |
|
2477 | function loopDestroy() {
|
2478 | const swiper = this;
|
2479 | const {
|
2480 | params,
|
2481 | slidesEl
|
2482 | } = swiper;
|
2483 | if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
|
2484 | swiper.recalcSlides();
|
2485 | const newSlidesOrder = [];
|
2486 | swiper.slides.forEach(slideEl => {
|
2487 | const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex;
|
2488 | newSlidesOrder[index] = slideEl;
|
2489 | });
|
2490 | swiper.slides.forEach(slideEl => {
|
2491 | slideEl.removeAttribute('data-swiper-slide-index');
|
2492 | });
|
2493 | newSlidesOrder.forEach(slideEl => {
|
2494 | slidesEl.append(slideEl);
|
2495 | });
|
2496 | swiper.recalcSlides();
|
2497 | swiper.slideTo(swiper.realIndex, 0);
|
2498 | }
|
2499 |
|
2500 | var loop = {
|
2501 | loopCreate,
|
2502 | loopFix,
|
2503 | loopDestroy
|
2504 | };
|
2505 |
|
2506 | function setGrabCursor(moving) {
|
2507 | const swiper = this;
|
2508 | if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
|
2509 | const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
|
2510 | if (swiper.isElement) {
|
2511 | swiper.__preventObserver__ = true;
|
2512 | }
|
2513 | el.style.cursor = 'move';
|
2514 | el.style.cursor = moving ? 'grabbing' : 'grab';
|
2515 | if (swiper.isElement) {
|
2516 | requestAnimationFrame(() => {
|
2517 | swiper.__preventObserver__ = false;
|
2518 | });
|
2519 | }
|
2520 | }
|
2521 |
|
2522 | function unsetGrabCursor() {
|
2523 | const swiper = this;
|
2524 | if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
|
2525 | return;
|
2526 | }
|
2527 | if (swiper.isElement) {
|
2528 | swiper.__preventObserver__ = true;
|
2529 | }
|
2530 | swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
|
2531 | if (swiper.isElement) {
|
2532 | requestAnimationFrame(() => {
|
2533 | swiper.__preventObserver__ = false;
|
2534 | });
|
2535 | }
|
2536 | }
|
2537 |
|
2538 | var grabCursor = {
|
2539 | setGrabCursor,
|
2540 | unsetGrabCursor
|
2541 | };
|
2542 |
|
2543 |
|
2544 | function closestElement(selector, base) {
|
2545 | if (base === void 0) {
|
2546 | base = this;
|
2547 | }
|
2548 | function __closestFrom(el) {
|
2549 | if (!el || el === getDocument() || el === getWindow()) return null;
|
2550 | if (el.assignedSlot) el = el.assignedSlot;
|
2551 | const found = el.closest(selector);
|
2552 | if (!found && !el.getRootNode) {
|
2553 | return null;
|
2554 | }
|
2555 | return found || __closestFrom(el.getRootNode().host);
|
2556 | }
|
2557 | return __closestFrom(base);
|
2558 | }
|
2559 | function preventEdgeSwipe(swiper, event, startX) {
|
2560 | const window = getWindow();
|
2561 | const {
|
2562 | params
|
2563 | } = swiper;
|
2564 | const edgeSwipeDetection = params.edgeSwipeDetection;
|
2565 | const edgeSwipeThreshold = params.edgeSwipeThreshold;
|
2566 | if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
|
2567 | if (edgeSwipeDetection === 'prevent') {
|
2568 | event.preventDefault();
|
2569 | return true;
|
2570 | }
|
2571 | return false;
|
2572 | }
|
2573 | return true;
|
2574 | }
|
2575 | function onTouchStart(event) {
|
2576 | const swiper = this;
|
2577 | const document = getDocument();
|
2578 | let e = event;
|
2579 | if (e.originalEvent) e = e.originalEvent;
|
2580 | const data = swiper.touchEventsData;
|
2581 | if (e.type === 'pointerdown') {
|
2582 | if (data.pointerId !== null && data.pointerId !== e.pointerId) {
|
2583 | return;
|
2584 | }
|
2585 | data.pointerId = e.pointerId;
|
2586 | } else if (e.type === 'touchstart' && e.targetTouches.length === 1) {
|
2587 | data.touchId = e.targetTouches[0].identifier;
|
2588 | }
|
2589 | if (e.type === 'touchstart') {
|
2590 |
|
2591 | preventEdgeSwipe(swiper, e, e.targetTouches[0].pageX);
|
2592 | return;
|
2593 | }
|
2594 | const {
|
2595 | params,
|
2596 | touches,
|
2597 | enabled
|
2598 | } = swiper;
|
2599 | if (!enabled) return;
|
2600 | if (!params.simulateTouch && e.pointerType === 'mouse') return;
|
2601 | if (swiper.animating && params.preventInteractionOnTransition) {
|
2602 | return;
|
2603 | }
|
2604 | if (!swiper.animating && params.cssMode && params.loop) {
|
2605 | swiper.loopFix();
|
2606 | }
|
2607 | let targetEl = e.target;
|
2608 | if (params.touchEventsTarget === 'wrapper') {
|
2609 | if (!swiper.wrapperEl.contains(targetEl)) return;
|
2610 | }
|
2611 | if ('which' in e && e.which === 3) return;
|
2612 | if ('button' in e && e.button > 0) return;
|
2613 | if (data.isTouched && data.isMoved) return;
|
2614 |
|
2615 |
|
2616 | const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== '';
|
2617 |
|
2618 | const eventPath = e.composedPath ? e.composedPath() : e.path;
|
2619 | if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) {
|
2620 | targetEl = eventPath[0];
|
2621 | }
|
2622 | const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
|
2623 | const isTargetShadow = !!(e.target && e.target.shadowRoot);
|
2624 |
|
2625 |
|
2626 | if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) {
|
2627 | swiper.allowClick = true;
|
2628 | return;
|
2629 | }
|
2630 | if (params.swipeHandler) {
|
2631 | if (!targetEl.closest(params.swipeHandler)) return;
|
2632 | }
|
2633 | touches.currentX = e.pageX;
|
2634 | touches.currentY = e.pageY;
|
2635 | const startX = touches.currentX;
|
2636 | const startY = touches.currentY;
|
2637 |
|
2638 |
|
2639 |
|
2640 | if (!preventEdgeSwipe(swiper, e, startX)) {
|
2641 | return;
|
2642 | }
|
2643 | Object.assign(data, {
|
2644 | isTouched: true,
|
2645 | isMoved: false,
|
2646 | allowTouchCallbacks: true,
|
2647 | isScrolling: undefined,
|
2648 | startMoving: undefined
|
2649 | });
|
2650 | touches.startX = startX;
|
2651 | touches.startY = startY;
|
2652 | data.touchStartTime = now();
|
2653 | swiper.allowClick = true;
|
2654 | swiper.updateSize();
|
2655 | swiper.swipeDirection = undefined;
|
2656 | if (params.threshold > 0) data.allowThresholdMove = false;
|
2657 | let preventDefault = true;
|
2658 | if (targetEl.matches(data.focusableElements)) {
|
2659 | preventDefault = false;
|
2660 | if (targetEl.nodeName === 'SELECT') {
|
2661 | data.isTouched = false;
|
2662 | }
|
2663 | }
|
2664 | if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl) {
|
2665 | document.activeElement.blur();
|
2666 | }
|
2667 | const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
|
2668 | if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) {
|
2669 | e.preventDefault();
|
2670 | }
|
2671 | if (params.freeMode && params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
|
2672 | swiper.freeMode.onTouchStart();
|
2673 | }
|
2674 | swiper.emit('touchStart', e);
|
2675 | }
|
2676 |
|
2677 | function onTouchMove(event) {
|
2678 | const document = getDocument();
|
2679 | const swiper = this;
|
2680 | const data = swiper.touchEventsData;
|
2681 | const {
|
2682 | params,
|
2683 | touches,
|
2684 | rtlTranslate: rtl,
|
2685 | enabled
|
2686 | } = swiper;
|
2687 | if (!enabled) return;
|
2688 | if (!params.simulateTouch && event.pointerType === 'mouse') return;
|
2689 | let e = event;
|
2690 | if (e.originalEvent) e = e.originalEvent;
|
2691 | if (e.type === 'pointermove') {
|
2692 | if (data.touchId !== null) return;
|
2693 | const id = e.pointerId;
|
2694 | if (id !== data.pointerId) return;
|
2695 | }
|
2696 | let targetTouch;
|
2697 | if (e.type === 'touchmove') {
|
2698 | targetTouch = [...e.changedTouches].filter(t => t.identifier === data.touchId)[0];
|
2699 | if (!targetTouch || targetTouch.identifier !== data.touchId) return;
|
2700 | } else {
|
2701 | targetTouch = e;
|
2702 | }
|
2703 | if (!data.isTouched) {
|
2704 | if (data.startMoving && data.isScrolling) {
|
2705 | swiper.emit('touchMoveOpposite', e);
|
2706 | }
|
2707 | return;
|
2708 | }
|
2709 | const pageX = targetTouch.pageX;
|
2710 | const pageY = targetTouch.pageY;
|
2711 | if (e.preventedByNestedSwiper) {
|
2712 | touches.startX = pageX;
|
2713 | touches.startY = pageY;
|
2714 | return;
|
2715 | }
|
2716 | if (!swiper.allowTouchMove) {
|
2717 | if (!e.target.matches(data.focusableElements)) {
|
2718 | swiper.allowClick = false;
|
2719 | }
|
2720 | if (data.isTouched) {
|
2721 | Object.assign(touches, {
|
2722 | startX: pageX,
|
2723 | startY: pageY,
|
2724 | currentX: pageX,
|
2725 | currentY: pageY
|
2726 | });
|
2727 | data.touchStartTime = now();
|
2728 | }
|
2729 | return;
|
2730 | }
|
2731 | if (params.touchReleaseOnEdges && !params.loop) {
|
2732 | if (swiper.isVertical()) {
|
2733 |
|
2734 | if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
|
2735 | data.isTouched = false;
|
2736 | data.isMoved = false;
|
2737 | return;
|
2738 | }
|
2739 | } else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) {
|
2740 | return;
|
2741 | }
|
2742 | }
|
2743 | if (document.activeElement) {
|
2744 | if (e.target === document.activeElement && e.target.matches(data.focusableElements)) {
|
2745 | data.isMoved = true;
|
2746 | swiper.allowClick = false;
|
2747 | return;
|
2748 | }
|
2749 | }
|
2750 | if (data.allowTouchCallbacks) {
|
2751 | swiper.emit('touchMove', e);
|
2752 | }
|
2753 | touches.previousX = touches.currentX;
|
2754 | touches.previousY = touches.currentY;
|
2755 | touches.currentX = pageX;
|
2756 | touches.currentY = pageY;
|
2757 | const diffX = touches.currentX - touches.startX;
|
2758 | const diffY = touches.currentY - touches.startY;
|
2759 | if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
|
2760 | if (typeof data.isScrolling === 'undefined') {
|
2761 | let touchAngle;
|
2762 | if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
|
2763 | data.isScrolling = false;
|
2764 | } else {
|
2765 |
|
2766 | if (diffX * diffX + diffY * diffY >= 25) {
|
2767 | touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
|
2768 | data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
|
2769 | }
|
2770 | }
|
2771 | }
|
2772 | if (data.isScrolling) {
|
2773 | swiper.emit('touchMoveOpposite', e);
|
2774 | }
|
2775 | if (typeof data.startMoving === 'undefined') {
|
2776 | if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
|
2777 | data.startMoving = true;
|
2778 | }
|
2779 | }
|
2780 | if (data.isScrolling || e.type === 'touchmove' && data.preventTouchMoveFromPointerMove) {
|
2781 | data.isTouched = false;
|
2782 | return;
|
2783 | }
|
2784 | if (!data.startMoving) {
|
2785 | return;
|
2786 | }
|
2787 | swiper.allowClick = false;
|
2788 | if (!params.cssMode && e.cancelable) {
|
2789 | e.preventDefault();
|
2790 | }
|
2791 | if (params.touchMoveStopPropagation && !params.nested) {
|
2792 | e.stopPropagation();
|
2793 | }
|
2794 | let diff = swiper.isHorizontal() ? diffX : diffY;
|
2795 | let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY;
|
2796 | if (params.oneWayMovement) {
|
2797 | diff = Math.abs(diff) * (rtl ? 1 : -1);
|
2798 | touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1);
|
2799 | }
|
2800 | touches.diff = diff;
|
2801 | diff *= params.touchRatio;
|
2802 | if (rtl) {
|
2803 | diff = -diff;
|
2804 | touchesDiff = -touchesDiff;
|
2805 | }
|
2806 | const prevTouchesDirection = swiper.touchesDirection;
|
2807 | swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
|
2808 | swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next';
|
2809 | const isLoop = swiper.params.loop && !params.cssMode;
|
2810 | const allowLoopFix = swiper.touchesDirection === 'next' && swiper.allowSlideNext || swiper.touchesDirection === 'prev' && swiper.allowSlidePrev;
|
2811 | if (!data.isMoved) {
|
2812 | if (isLoop && allowLoopFix) {
|
2813 | swiper.loopFix({
|
2814 | direction: swiper.swipeDirection
|
2815 | });
|
2816 | }
|
2817 | data.startTranslate = swiper.getTranslate();
|
2818 | swiper.setTransition(0);
|
2819 | if (swiper.animating) {
|
2820 | const evt = new window.CustomEvent('transitionend', {
|
2821 | bubbles: true,
|
2822 | cancelable: true,
|
2823 | detail: {
|
2824 | bySwiperTouchMove: true
|
2825 | }
|
2826 | });
|
2827 | swiper.wrapperEl.dispatchEvent(evt);
|
2828 | }
|
2829 | data.allowMomentumBounce = false;
|
2830 |
|
2831 | if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
|
2832 | swiper.setGrabCursor(true);
|
2833 | }
|
2834 | swiper.emit('sliderFirstMove', e);
|
2835 | }
|
2836 | let loopFixed;
|
2837 | new Date().getTime();
|
2838 | if (data.isMoved && data.allowThresholdMove && prevTouchesDirection !== swiper.touchesDirection && isLoop && allowLoopFix && Math.abs(diff) >= 1) {
|
2839 | Object.assign(touches, {
|
2840 | startX: pageX,
|
2841 | startY: pageY,
|
2842 | currentX: pageX,
|
2843 | currentY: pageY,
|
2844 | startTranslate: data.currentTranslate
|
2845 | });
|
2846 | data.loopSwapReset = true;
|
2847 | data.startTranslate = data.currentTranslate;
|
2848 | return;
|
2849 | }
|
2850 | swiper.emit('sliderMove', e);
|
2851 | data.isMoved = true;
|
2852 | data.currentTranslate = diff + data.startTranslate;
|
2853 | let disableParentSwiper = true;
|
2854 | let resistanceRatio = params.resistanceRatio;
|
2855 | if (params.touchReleaseOnEdges) {
|
2856 | resistanceRatio = 0;
|
2857 | }
|
2858 | if (diff > 0) {
|
2859 | if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.slidesSizesGrid[swiper.activeIndex + 1] : swiper.minTranslate())) {
|
2860 | swiper.loopFix({
|
2861 | direction: 'prev',
|
2862 | setTranslate: true,
|
2863 | activeSlideIndex: 0
|
2864 | });
|
2865 | }
|
2866 | if (data.currentTranslate > swiper.minTranslate()) {
|
2867 | disableParentSwiper = false;
|
2868 | if (params.resistance) {
|
2869 | data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
|
2870 | }
|
2871 | }
|
2872 | } else if (diff < 0) {
|
2873 | if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] : swiper.maxTranslate())) {
|
2874 | swiper.loopFix({
|
2875 | direction: 'next',
|
2876 | setTranslate: true,
|
2877 | activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)))
|
2878 | });
|
2879 | }
|
2880 | if (data.currentTranslate < swiper.maxTranslate()) {
|
2881 | disableParentSwiper = false;
|
2882 | if (params.resistance) {
|
2883 | data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
|
2884 | }
|
2885 | }
|
2886 | }
|
2887 | if (disableParentSwiper) {
|
2888 | e.preventedByNestedSwiper = true;
|
2889 | }
|
2890 |
|
2891 |
|
2892 | if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
|
2893 | data.currentTranslate = data.startTranslate;
|
2894 | }
|
2895 | if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
|
2896 | data.currentTranslate = data.startTranslate;
|
2897 | }
|
2898 | if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
|
2899 | data.currentTranslate = data.startTranslate;
|
2900 | }
|
2901 |
|
2902 |
|
2903 | if (params.threshold > 0) {
|
2904 | if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
|
2905 | if (!data.allowThresholdMove) {
|
2906 | data.allowThresholdMove = true;
|
2907 | touches.startX = touches.currentX;
|
2908 | touches.startY = touches.currentY;
|
2909 | data.currentTranslate = data.startTranslate;
|
2910 | touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
|
2911 | return;
|
2912 | }
|
2913 | } else {
|
2914 | data.currentTranslate = data.startTranslate;
|
2915 | return;
|
2916 | }
|
2917 | }
|
2918 | if (!params.followFinger || params.cssMode) return;
|
2919 |
|
2920 |
|
2921 | if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
|
2922 | swiper.updateActiveIndex();
|
2923 | swiper.updateSlidesClasses();
|
2924 | }
|
2925 | if (params.freeMode && params.freeMode.enabled && swiper.freeMode) {
|
2926 | swiper.freeMode.onTouchMove();
|
2927 | }
|
2928 |
|
2929 | swiper.updateProgress(data.currentTranslate);
|
2930 |
|
2931 | swiper.setTranslate(data.currentTranslate);
|
2932 | }
|
2933 |
|
2934 | function onTouchEnd(event) {
|
2935 | const swiper = this;
|
2936 | const data = swiper.touchEventsData;
|
2937 | let e = event;
|
2938 | if (e.originalEvent) e = e.originalEvent;
|
2939 | let targetTouch;
|
2940 | const isTouchEvent = e.type === 'touchend' || e.type === 'touchcancel';
|
2941 | if (!isTouchEvent) {
|
2942 | if (data.touchId !== null) return;
|
2943 | if (e.pointerId !== data.pointerId) return;
|
2944 | targetTouch = e;
|
2945 | } else {
|
2946 | targetTouch = [...e.changedTouches].filter(t => t.identifier === data.touchId)[0];
|
2947 | if (!targetTouch || targetTouch.identifier !== data.touchId) return;
|
2948 | }
|
2949 | if (['pointercancel', 'pointerout', 'pointerleave', 'contextmenu'].includes(e.type)) {
|
2950 | const proceed = ['pointercancel', 'contextmenu'].includes(e.type) && (swiper.browser.isSafari || swiper.browser.isWebView);
|
2951 | if (!proceed) {
|
2952 | return;
|
2953 | }
|
2954 | }
|
2955 | data.pointerId = null;
|
2956 | data.touchId = null;
|
2957 | const {
|
2958 | params,
|
2959 | touches,
|
2960 | rtlTranslate: rtl,
|
2961 | slidesGrid,
|
2962 | enabled
|
2963 | } = swiper;
|
2964 | if (!enabled) return;
|
2965 | if (!params.simulateTouch && e.pointerType === 'mouse') return;
|
2966 | if (data.allowTouchCallbacks) {
|
2967 | swiper.emit('touchEnd', e);
|
2968 | }
|
2969 | data.allowTouchCallbacks = false;
|
2970 | if (!data.isTouched) {
|
2971 | if (data.isMoved && params.grabCursor) {
|
2972 | swiper.setGrabCursor(false);
|
2973 | }
|
2974 | data.isMoved = false;
|
2975 | data.startMoving = false;
|
2976 | return;
|
2977 | }
|
2978 |
|
2979 |
|
2980 | if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
|
2981 | swiper.setGrabCursor(false);
|
2982 | }
|
2983 |
|
2984 |
|
2985 | const touchEndTime = now();
|
2986 | const timeDiff = touchEndTime - data.touchStartTime;
|
2987 |
|
2988 |
|
2989 | if (swiper.allowClick) {
|
2990 | const pathTree = e.path || e.composedPath && e.composedPath();
|
2991 | swiper.updateClickedSlide(pathTree && pathTree[0] || e.target, pathTree);
|
2992 | swiper.emit('tap click', e);
|
2993 | if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
|
2994 | swiper.emit('doubleTap doubleClick', e);
|
2995 | }
|
2996 | }
|
2997 | data.lastClickTime = now();
|
2998 | nextTick(() => {
|
2999 | if (!swiper.destroyed) swiper.allowClick = true;
|
3000 | });
|
3001 | if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 && !data.loopSwapReset || data.currentTranslate === data.startTranslate && !data.loopSwapReset) {
|
3002 | data.isTouched = false;
|
3003 | data.isMoved = false;
|
3004 | data.startMoving = false;
|
3005 | return;
|
3006 | }
|
3007 | data.isTouched = false;
|
3008 | data.isMoved = false;
|
3009 | data.startMoving = false;
|
3010 | let currentPos;
|
3011 | if (params.followFinger) {
|
3012 | currentPos = rtl ? swiper.translate : -swiper.translate;
|
3013 | } else {
|
3014 | currentPos = -data.currentTranslate;
|
3015 | }
|
3016 | if (params.cssMode) {
|
3017 | return;
|
3018 | }
|
3019 | if (params.freeMode && params.freeMode.enabled) {
|
3020 | swiper.freeMode.onTouchEnd({
|
3021 | currentPos
|
3022 | });
|
3023 | return;
|
3024 | }
|
3025 |
|
3026 |
|
3027 | const swipeToLast = currentPos >= -swiper.maxTranslate() && !swiper.params.loop;
|
3028 | let stopIndex = 0;
|
3029 | let groupSize = swiper.slidesSizesGrid[0];
|
3030 | for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
|
3031 | const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
|
3032 | if (typeof slidesGrid[i + increment] !== 'undefined') {
|
3033 | if (swipeToLast || currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
|
3034 | stopIndex = i;
|
3035 | groupSize = slidesGrid[i + increment] - slidesGrid[i];
|
3036 | }
|
3037 | } else if (swipeToLast || currentPos >= slidesGrid[i]) {
|
3038 | stopIndex = i;
|
3039 | groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
|
3040 | }
|
3041 | }
|
3042 | let rewindFirstIndex = null;
|
3043 | let rewindLastIndex = null;
|
3044 | if (params.rewind) {
|
3045 | if (swiper.isBeginning) {
|
3046 | rewindLastIndex = params.virtual && params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
|
3047 | } else if (swiper.isEnd) {
|
3048 | rewindFirstIndex = 0;
|
3049 | }
|
3050 | }
|
3051 |
|
3052 | const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
|
3053 | const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
|
3054 | if (timeDiff > params.longSwipesMs) {
|
3055 |
|
3056 | if (!params.longSwipes) {
|
3057 | swiper.slideTo(swiper.activeIndex);
|
3058 | return;
|
3059 | }
|
3060 | if (swiper.swipeDirection === 'next') {
|
3061 | if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
|
3062 | }
|
3063 | if (swiper.swipeDirection === 'prev') {
|
3064 | if (ratio > 1 - params.longSwipesRatio) {
|
3065 | swiper.slideTo(stopIndex + increment);
|
3066 | } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
|
3067 | swiper.slideTo(rewindLastIndex);
|
3068 | } else {
|
3069 | swiper.slideTo(stopIndex);
|
3070 | }
|
3071 | }
|
3072 | } else {
|
3073 |
|
3074 | if (!params.shortSwipes) {
|
3075 | swiper.slideTo(swiper.activeIndex);
|
3076 | return;
|
3077 | }
|
3078 | const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
|
3079 | if (!isNavButtonTarget) {
|
3080 | if (swiper.swipeDirection === 'next') {
|
3081 | swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
|
3082 | }
|
3083 | if (swiper.swipeDirection === 'prev') {
|
3084 | swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
|
3085 | }
|
3086 | } else if (e.target === swiper.navigation.nextEl) {
|
3087 | swiper.slideTo(stopIndex + increment);
|
3088 | } else {
|
3089 | swiper.slideTo(stopIndex);
|
3090 | }
|
3091 | }
|
3092 | }
|
3093 |
|
3094 | function onResize() {
|
3095 | const swiper = this;
|
3096 | const {
|
3097 | params,
|
3098 | el
|
3099 | } = swiper;
|
3100 | if (el && el.offsetWidth === 0) return;
|
3101 |
|
3102 |
|
3103 | if (params.breakpoints) {
|
3104 | swiper.setBreakpoint();
|
3105 | }
|
3106 |
|
3107 |
|
3108 | const {
|
3109 | allowSlideNext,
|
3110 | allowSlidePrev,
|
3111 | snapGrid
|
3112 | } = swiper;
|
3113 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
3114 |
|
3115 |
|
3116 | swiper.allowSlideNext = true;
|
3117 | swiper.allowSlidePrev = true;
|
3118 | swiper.updateSize();
|
3119 | swiper.updateSlides();
|
3120 | swiper.updateSlidesClasses();
|
3121 | const isVirtualLoop = isVirtual && params.loop;
|
3122 | if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) {
|
3123 | swiper.slideTo(swiper.slides.length - 1, 0, false, true);
|
3124 | } else {
|
3125 | if (swiper.params.loop && !isVirtual) {
|
3126 | swiper.slideToLoop(swiper.realIndex, 0, false, true);
|
3127 | } else {
|
3128 | swiper.slideTo(swiper.activeIndex, 0, false, true);
|
3129 | }
|
3130 | }
|
3131 | if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
|
3132 | clearTimeout(swiper.autoplay.resizeTimeout);
|
3133 | swiper.autoplay.resizeTimeout = setTimeout(() => {
|
3134 | if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
|
3135 | swiper.autoplay.resume();
|
3136 | }
|
3137 | }, 500);
|
3138 | }
|
3139 |
|
3140 | swiper.allowSlidePrev = allowSlidePrev;
|
3141 | swiper.allowSlideNext = allowSlideNext;
|
3142 | if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
|
3143 | swiper.checkOverflow();
|
3144 | }
|
3145 | }
|
3146 |
|
3147 | function onClick(e) {
|
3148 | const swiper = this;
|
3149 | if (!swiper.enabled) return;
|
3150 | if (!swiper.allowClick) {
|
3151 | if (swiper.params.preventClicks) e.preventDefault();
|
3152 | if (swiper.params.preventClicksPropagation && swiper.animating) {
|
3153 | e.stopPropagation();
|
3154 | e.stopImmediatePropagation();
|
3155 | }
|
3156 | }
|
3157 | }
|
3158 |
|
3159 | function onScroll() {
|
3160 | const swiper = this;
|
3161 | const {
|
3162 | wrapperEl,
|
3163 | rtlTranslate,
|
3164 | enabled
|
3165 | } = swiper;
|
3166 | if (!enabled) return;
|
3167 | swiper.previousTranslate = swiper.translate;
|
3168 | if (swiper.isHorizontal()) {
|
3169 | swiper.translate = -wrapperEl.scrollLeft;
|
3170 | } else {
|
3171 | swiper.translate = -wrapperEl.scrollTop;
|
3172 | }
|
3173 |
|
3174 | if (swiper.translate === 0) swiper.translate = 0;
|
3175 | swiper.updateActiveIndex();
|
3176 | swiper.updateSlidesClasses();
|
3177 | let newProgress;
|
3178 | const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
3179 | if (translatesDiff === 0) {
|
3180 | newProgress = 0;
|
3181 | } else {
|
3182 | newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
|
3183 | }
|
3184 | if (newProgress !== swiper.progress) {
|
3185 | swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
|
3186 | }
|
3187 | swiper.emit('setTranslate', swiper.translate, false);
|
3188 | }
|
3189 |
|
3190 | function onLoad(e) {
|
3191 | const swiper = this;
|
3192 | processLazyPreloader(swiper, e.target);
|
3193 | if (swiper.params.cssMode || swiper.params.slidesPerView !== 'auto' && !swiper.params.autoHeight) {
|
3194 | return;
|
3195 | }
|
3196 | swiper.update();
|
3197 | }
|
3198 |
|
3199 | function onDocumentTouchStart() {
|
3200 | const swiper = this;
|
3201 | if (swiper.documentTouchHandlerProceeded) return;
|
3202 | swiper.documentTouchHandlerProceeded = true;
|
3203 | if (swiper.params.touchReleaseOnEdges) {
|
3204 | swiper.el.style.touchAction = 'auto';
|
3205 | }
|
3206 | }
|
3207 |
|
3208 | const events = (swiper, method) => {
|
3209 | const document = getDocument();
|
3210 | const {
|
3211 | params,
|
3212 | el,
|
3213 | wrapperEl,
|
3214 | device
|
3215 | } = swiper;
|
3216 | const capture = !!params.nested;
|
3217 | const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
|
3218 | const swiperMethod = method;
|
3219 | if (!el || typeof el === 'string') return;
|
3220 |
|
3221 |
|
3222 | document[domMethod]('touchstart', swiper.onDocumentTouchStart, {
|
3223 | passive: false,
|
3224 | capture
|
3225 | });
|
3226 | el[domMethod]('touchstart', swiper.onTouchStart, {
|
3227 | passive: false
|
3228 | });
|
3229 | el[domMethod]('pointerdown', swiper.onTouchStart, {
|
3230 | passive: false
|
3231 | });
|
3232 | document[domMethod]('touchmove', swiper.onTouchMove, {
|
3233 | passive: false,
|
3234 | capture
|
3235 | });
|
3236 | document[domMethod]('pointermove', swiper.onTouchMove, {
|
3237 | passive: false,
|
3238 | capture
|
3239 | });
|
3240 | document[domMethod]('touchend', swiper.onTouchEnd, {
|
3241 | passive: true
|
3242 | });
|
3243 | document[domMethod]('pointerup', swiper.onTouchEnd, {
|
3244 | passive: true
|
3245 | });
|
3246 | document[domMethod]('pointercancel', swiper.onTouchEnd, {
|
3247 | passive: true
|
3248 | });
|
3249 | document[domMethod]('touchcancel', swiper.onTouchEnd, {
|
3250 | passive: true
|
3251 | });
|
3252 | document[domMethod]('pointerout', swiper.onTouchEnd, {
|
3253 | passive: true
|
3254 | });
|
3255 | document[domMethod]('pointerleave', swiper.onTouchEnd, {
|
3256 | passive: true
|
3257 | });
|
3258 | document[domMethod]('contextmenu', swiper.onTouchEnd, {
|
3259 | passive: true
|
3260 | });
|
3261 |
|
3262 |
|
3263 | if (params.preventClicks || params.preventClicksPropagation) {
|
3264 | el[domMethod]('click', swiper.onClick, true);
|
3265 | }
|
3266 | if (params.cssMode) {
|
3267 | wrapperEl[domMethod]('scroll', swiper.onScroll);
|
3268 | }
|
3269 |
|
3270 |
|
3271 | if (params.updateOnWindowResize) {
|
3272 | swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true);
|
3273 | } else {
|
3274 | swiper[swiperMethod]('observerUpdate', onResize, true);
|
3275 | }
|
3276 |
|
3277 |
|
3278 | el[domMethod]('load', swiper.onLoad, {
|
3279 | capture: true
|
3280 | });
|
3281 | };
|
3282 | function attachEvents() {
|
3283 | const swiper = this;
|
3284 | const {
|
3285 | params
|
3286 | } = swiper;
|
3287 | swiper.onTouchStart = onTouchStart.bind(swiper);
|
3288 | swiper.onTouchMove = onTouchMove.bind(swiper);
|
3289 | swiper.onTouchEnd = onTouchEnd.bind(swiper);
|
3290 | swiper.onDocumentTouchStart = onDocumentTouchStart.bind(swiper);
|
3291 | if (params.cssMode) {
|
3292 | swiper.onScroll = onScroll.bind(swiper);
|
3293 | }
|
3294 | swiper.onClick = onClick.bind(swiper);
|
3295 | swiper.onLoad = onLoad.bind(swiper);
|
3296 | events(swiper, 'on');
|
3297 | }
|
3298 | function detachEvents() {
|
3299 | const swiper = this;
|
3300 | events(swiper, 'off');
|
3301 | }
|
3302 | var events$1 = {
|
3303 | attachEvents,
|
3304 | detachEvents
|
3305 | };
|
3306 |
|
3307 | const isGridEnabled = (swiper, params) => {
|
3308 | return swiper.grid && params.grid && params.grid.rows > 1;
|
3309 | };
|
3310 | function setBreakpoint() {
|
3311 | const swiper = this;
|
3312 | const {
|
3313 | realIndex,
|
3314 | initialized,
|
3315 | params,
|
3316 | el
|
3317 | } = swiper;
|
3318 | const breakpoints = params.breakpoints;
|
3319 | if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
|
3320 |
|
3321 |
|
3322 | const breakpoint = swiper.getBreakpoint(breakpoints, swiper.params.breakpointsBase, swiper.el);
|
3323 | if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
|
3324 | const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
|
3325 | const breakpointParams = breakpointOnlyParams || swiper.originalParams;
|
3326 | const wasMultiRow = isGridEnabled(swiper, params);
|
3327 | const isMultiRow = isGridEnabled(swiper, breakpointParams);
|
3328 | const wasGrabCursor = swiper.params.grabCursor;
|
3329 | const isGrabCursor = breakpointParams.grabCursor;
|
3330 | const wasEnabled = params.enabled;
|
3331 | if (wasMultiRow && !isMultiRow) {
|
3332 | el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`);
|
3333 | swiper.emitContainerClasses();
|
3334 | } else if (!wasMultiRow && isMultiRow) {
|
3335 | el.classList.add(`${params.containerModifierClass}grid`);
|
3336 | if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
|
3337 | el.classList.add(`${params.containerModifierClass}grid-column`);
|
3338 | }
|
3339 | swiper.emitContainerClasses();
|
3340 | }
|
3341 | if (wasGrabCursor && !isGrabCursor) {
|
3342 | swiper.unsetGrabCursor();
|
3343 | } else if (!wasGrabCursor && isGrabCursor) {
|
3344 | swiper.setGrabCursor();
|
3345 | }
|
3346 |
|
3347 |
|
3348 | ['navigation', 'pagination', 'scrollbar'].forEach(prop => {
|
3349 | if (typeof breakpointParams[prop] === 'undefined') return;
|
3350 | const wasModuleEnabled = params[prop] && params[prop].enabled;
|
3351 | const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled;
|
3352 | if (wasModuleEnabled && !isModuleEnabled) {
|
3353 | swiper[prop].disable();
|
3354 | }
|
3355 | if (!wasModuleEnabled && isModuleEnabled) {
|
3356 | swiper[prop].enable();
|
3357 | }
|
3358 | });
|
3359 | const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
|
3360 | const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
|
3361 | const wasLoop = params.loop;
|
3362 | if (directionChanged && initialized) {
|
3363 | swiper.changeDirection();
|
3364 | }
|
3365 | extend$1(swiper.params, breakpointParams);
|
3366 | const isEnabled = swiper.params.enabled;
|
3367 | const hasLoop = swiper.params.loop;
|
3368 | Object.assign(swiper, {
|
3369 | allowTouchMove: swiper.params.allowTouchMove,
|
3370 | allowSlideNext: swiper.params.allowSlideNext,
|
3371 | allowSlidePrev: swiper.params.allowSlidePrev
|
3372 | });
|
3373 | if (wasEnabled && !isEnabled) {
|
3374 | swiper.disable();
|
3375 | } else if (!wasEnabled && isEnabled) {
|
3376 | swiper.enable();
|
3377 | }
|
3378 | swiper.currentBreakpoint = breakpoint;
|
3379 | swiper.emit('_beforeBreakpoint', breakpointParams);
|
3380 | if (initialized) {
|
3381 | if (needsReLoop) {
|
3382 | swiper.loopDestroy();
|
3383 | swiper.loopCreate(realIndex);
|
3384 | swiper.updateSlides();
|
3385 | } else if (!wasLoop && hasLoop) {
|
3386 | swiper.loopCreate(realIndex);
|
3387 | swiper.updateSlides();
|
3388 | } else if (wasLoop && !hasLoop) {
|
3389 | swiper.loopDestroy();
|
3390 | }
|
3391 | }
|
3392 | swiper.emit('breakpoint', breakpointParams);
|
3393 | }
|
3394 |
|
3395 | function getBreakpoint(breakpoints, base, containerEl) {
|
3396 | if (base === void 0) {
|
3397 | base = 'window';
|
3398 | }
|
3399 | if (!breakpoints || base === 'container' && !containerEl) return undefined;
|
3400 | let breakpoint = false;
|
3401 | const window = getWindow();
|
3402 | const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight;
|
3403 | const points = Object.keys(breakpoints).map(point => {
|
3404 | if (typeof point === 'string' && point.indexOf('@') === 0) {
|
3405 | const minRatio = parseFloat(point.substr(1));
|
3406 | const value = currentHeight * minRatio;
|
3407 | return {
|
3408 | value,
|
3409 | point
|
3410 | };
|
3411 | }
|
3412 | return {
|
3413 | value: point,
|
3414 | point
|
3415 | };
|
3416 | });
|
3417 | points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
|
3418 | for (let i = 0; i < points.length; i += 1) {
|
3419 | const {
|
3420 | point,
|
3421 | value
|
3422 | } = points[i];
|
3423 | if (base === 'window') {
|
3424 | if (window.matchMedia(`(min-width: ${value}px)`).matches) {
|
3425 | breakpoint = point;
|
3426 | }
|
3427 | } else if (value <= containerEl.clientWidth) {
|
3428 | breakpoint = point;
|
3429 | }
|
3430 | }
|
3431 | return breakpoint || 'max';
|
3432 | }
|
3433 |
|
3434 | var breakpoints = {
|
3435 | setBreakpoint,
|
3436 | getBreakpoint
|
3437 | };
|
3438 |
|
3439 | function prepareClasses(entries, prefix) {
|
3440 | const resultClasses = [];
|
3441 | entries.forEach(item => {
|
3442 | if (typeof item === 'object') {
|
3443 | Object.keys(item).forEach(classNames => {
|
3444 | if (item[classNames]) {
|
3445 | resultClasses.push(prefix + classNames);
|
3446 | }
|
3447 | });
|
3448 | } else if (typeof item === 'string') {
|
3449 | resultClasses.push(prefix + item);
|
3450 | }
|
3451 | });
|
3452 | return resultClasses;
|
3453 | }
|
3454 | function addClasses() {
|
3455 | const swiper = this;
|
3456 | const {
|
3457 | classNames,
|
3458 | params,
|
3459 | rtl,
|
3460 | el,
|
3461 | device
|
3462 | } = swiper;
|
3463 |
|
3464 | const suffixes = prepareClasses(['initialized', params.direction, {
|
3465 | 'free-mode': swiper.params.freeMode && params.freeMode.enabled
|
3466 | }, {
|
3467 | 'autoheight': params.autoHeight
|
3468 | }, {
|
3469 | 'rtl': rtl
|
3470 | }, {
|
3471 | 'grid': params.grid && params.grid.rows > 1
|
3472 | }, {
|
3473 | 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
|
3474 | }, {
|
3475 | 'android': device.android
|
3476 | }, {
|
3477 | 'ios': device.ios
|
3478 | }, {
|
3479 | 'css-mode': params.cssMode
|
3480 | }, {
|
3481 | 'centered': params.cssMode && params.centeredSlides
|
3482 | }, {
|
3483 | 'watch-progress': params.watchSlidesProgress
|
3484 | }], params.containerModifierClass);
|
3485 | classNames.push(...suffixes);
|
3486 | el.classList.add(...classNames);
|
3487 | swiper.emitContainerClasses();
|
3488 | }
|
3489 |
|
3490 | function removeClasses() {
|
3491 | const swiper = this;
|
3492 | const {
|
3493 | el,
|
3494 | classNames
|
3495 | } = swiper;
|
3496 | if (!el || typeof el === 'string') return;
|
3497 | el.classList.remove(...classNames);
|
3498 | swiper.emitContainerClasses();
|
3499 | }
|
3500 |
|
3501 | var classes = {
|
3502 | addClasses,
|
3503 | removeClasses
|
3504 | };
|
3505 |
|
3506 | function checkOverflow() {
|
3507 | const swiper = this;
|
3508 | const {
|
3509 | isLocked: wasLocked,
|
3510 | params
|
3511 | } = swiper;
|
3512 | const {
|
3513 | slidesOffsetBefore
|
3514 | } = params;
|
3515 | if (slidesOffsetBefore) {
|
3516 | const lastSlideIndex = swiper.slides.length - 1;
|
3517 | const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
|
3518 | swiper.isLocked = swiper.size > lastSlideRightEdge;
|
3519 | } else {
|
3520 | swiper.isLocked = swiper.snapGrid.length === 1;
|
3521 | }
|
3522 | if (params.allowSlideNext === true) {
|
3523 | swiper.allowSlideNext = !swiper.isLocked;
|
3524 | }
|
3525 | if (params.allowSlidePrev === true) {
|
3526 | swiper.allowSlidePrev = !swiper.isLocked;
|
3527 | }
|
3528 | if (wasLocked && wasLocked !== swiper.isLocked) {
|
3529 | swiper.isEnd = false;
|
3530 | }
|
3531 | if (wasLocked !== swiper.isLocked) {
|
3532 | swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
|
3533 | }
|
3534 | }
|
3535 | var checkOverflow$1 = {
|
3536 | checkOverflow
|
3537 | };
|
3538 |
|
3539 | var defaults = {
|
3540 | init: true,
|
3541 | direction: 'horizontal',
|
3542 | oneWayMovement: false,
|
3543 | swiperElementNodeName: 'SWIPER-CONTAINER',
|
3544 | touchEventsTarget: 'wrapper',
|
3545 | initialSlide: 0,
|
3546 | speed: 300,
|
3547 | cssMode: false,
|
3548 | updateOnWindowResize: true,
|
3549 | resizeObserver: true,
|
3550 | nested: false,
|
3551 | createElements: false,
|
3552 | eventsPrefix: 'swiper',
|
3553 | enabled: true,
|
3554 | focusableElements: 'input, select, option, textarea, button, video, label',
|
3555 |
|
3556 | width: null,
|
3557 | height: null,
|
3558 |
|
3559 | preventInteractionOnTransition: false,
|
3560 |
|
3561 | userAgent: null,
|
3562 | url: null,
|
3563 |
|
3564 | edgeSwipeDetection: false,
|
3565 | edgeSwipeThreshold: 20,
|
3566 |
|
3567 | autoHeight: false,
|
3568 |
|
3569 | setWrapperSize: false,
|
3570 |
|
3571 | virtualTranslate: false,
|
3572 |
|
3573 | effect: 'slide',
|
3574 |
|
3575 |
|
3576 |
|
3577 | breakpoints: undefined,
|
3578 | breakpointsBase: 'window',
|
3579 |
|
3580 | spaceBetween: 0,
|
3581 | slidesPerView: 1,
|
3582 | slidesPerGroup: 1,
|
3583 | slidesPerGroupSkip: 0,
|
3584 | slidesPerGroupAuto: false,
|
3585 | centeredSlides: false,
|
3586 | centeredSlidesBounds: false,
|
3587 | slidesOffsetBefore: 0,
|
3588 |
|
3589 | slidesOffsetAfter: 0,
|
3590 |
|
3591 | normalizeSlideIndex: true,
|
3592 | centerInsufficientSlides: false,
|
3593 |
|
3594 | watchOverflow: true,
|
3595 |
|
3596 | roundLengths: false,
|
3597 |
|
3598 | touchRatio: 1,
|
3599 | touchAngle: 45,
|
3600 | simulateTouch: true,
|
3601 | shortSwipes: true,
|
3602 | longSwipes: true,
|
3603 | longSwipesRatio: 0.5,
|
3604 | longSwipesMs: 300,
|
3605 | followFinger: true,
|
3606 | allowTouchMove: true,
|
3607 | threshold: 5,
|
3608 | touchMoveStopPropagation: false,
|
3609 | touchStartPreventDefault: true,
|
3610 | touchStartForcePreventDefault: false,
|
3611 | touchReleaseOnEdges: false,
|
3612 |
|
3613 | uniqueNavElements: true,
|
3614 |
|
3615 | resistance: true,
|
3616 | resistanceRatio: 0.85,
|
3617 |
|
3618 | watchSlidesProgress: false,
|
3619 |
|
3620 | grabCursor: false,
|
3621 |
|
3622 | preventClicks: true,
|
3623 | preventClicksPropagation: true,
|
3624 | slideToClickedSlide: false,
|
3625 |
|
3626 | loop: false,
|
3627 | loopAddBlankSlides: true,
|
3628 | loopAdditionalSlides: 0,
|
3629 | loopPreventsSliding: true,
|
3630 |
|
3631 | rewind: false,
|
3632 |
|
3633 | allowSlidePrev: true,
|
3634 | allowSlideNext: true,
|
3635 | swipeHandler: null,
|
3636 |
|
3637 | noSwiping: true,
|
3638 | noSwipingClass: 'swiper-no-swiping',
|
3639 | noSwipingSelector: null,
|
3640 |
|
3641 | passiveListeners: true,
|
3642 | maxBackfaceHiddenSlides: 10,
|
3643 |
|
3644 | containerModifierClass: 'swiper-',
|
3645 |
|
3646 | slideClass: 'swiper-slide',
|
3647 | slideBlankClass: 'swiper-slide-blank',
|
3648 | slideActiveClass: 'swiper-slide-active',
|
3649 | slideVisibleClass: 'swiper-slide-visible',
|
3650 | slideFullyVisibleClass: 'swiper-slide-fully-visible',
|
3651 | slideNextClass: 'swiper-slide-next',
|
3652 | slidePrevClass: 'swiper-slide-prev',
|
3653 | wrapperClass: 'swiper-wrapper',
|
3654 | lazyPreloaderClass: 'swiper-lazy-preloader',
|
3655 | lazyPreloadPrevNext: 0,
|
3656 |
|
3657 | runCallbacksOnInit: true,
|
3658 |
|
3659 | _emitClasses: false
|
3660 | };
|
3661 |
|
3662 | function moduleExtendParams(params, allModulesParams) {
|
3663 | return function extendParams(obj) {
|
3664 | if (obj === void 0) {
|
3665 | obj = {};
|
3666 | }
|
3667 | const moduleParamName = Object.keys(obj)[0];
|
3668 | const moduleParams = obj[moduleParamName];
|
3669 | if (typeof moduleParams !== 'object' || moduleParams === null) {
|
3670 | extend$1(allModulesParams, obj);
|
3671 | return;
|
3672 | }
|
3673 | if (params[moduleParamName] === true) {
|
3674 | params[moduleParamName] = {
|
3675 | enabled: true
|
3676 | };
|
3677 | }
|
3678 | if (moduleParamName === 'navigation' && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].prevEl && !params[moduleParamName].nextEl) {
|
3679 | params[moduleParamName].auto = true;
|
3680 | }
|
3681 | if (['pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].el) {
|
3682 | params[moduleParamName].auto = true;
|
3683 | }
|
3684 | if (!(moduleParamName in params && 'enabled' in moduleParams)) {
|
3685 | extend$1(allModulesParams, obj);
|
3686 | return;
|
3687 | }
|
3688 | if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) {
|
3689 | params[moduleParamName].enabled = true;
|
3690 | }
|
3691 | if (!params[moduleParamName]) params[moduleParamName] = {
|
3692 | enabled: false
|
3693 | };
|
3694 | extend$1(allModulesParams, obj);
|
3695 | };
|
3696 | }
|
3697 |
|
3698 |
|
3699 | const prototypes = {
|
3700 | eventsEmitter,
|
3701 | update,
|
3702 | translate,
|
3703 | transition,
|
3704 | slide,
|
3705 | loop,
|
3706 | grabCursor,
|
3707 | events: events$1,
|
3708 | breakpoints,
|
3709 | checkOverflow: checkOverflow$1,
|
3710 | classes
|
3711 | };
|
3712 | const extendedDefaults = {};
|
3713 | class Swiper {
|
3714 | constructor() {
|
3715 | let el;
|
3716 | let params;
|
3717 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3718 | args[_key] = arguments[_key];
|
3719 | }
|
3720 | if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') {
|
3721 | params = args[0];
|
3722 | } else {
|
3723 | [el, params] = args;
|
3724 | }
|
3725 | if (!params) params = {};
|
3726 | params = extend$1({}, params);
|
3727 | if (el && !params.el) params.el = el;
|
3728 | const document = getDocument();
|
3729 | if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) {
|
3730 | const swipers = [];
|
3731 | document.querySelectorAll(params.el).forEach(containerEl => {
|
3732 | const newParams = extend$1({}, params, {
|
3733 | el: containerEl
|
3734 | });
|
3735 | swipers.push(new Swiper(newParams));
|
3736 | });
|
3737 |
|
3738 | return swipers;
|
3739 | }
|
3740 |
|
3741 |
|
3742 | const swiper = this;
|
3743 | swiper.__swiper__ = true;
|
3744 | swiper.support = getSupport();
|
3745 | swiper.device = getDevice({
|
3746 | userAgent: params.userAgent
|
3747 | });
|
3748 | swiper.browser = getBrowser();
|
3749 | swiper.eventsListeners = {};
|
3750 | swiper.eventsAnyListeners = [];
|
3751 | swiper.modules = [...swiper.__modules__];
|
3752 | if (params.modules && Array.isArray(params.modules)) {
|
3753 | swiper.modules.push(...params.modules);
|
3754 | }
|
3755 | const allModulesParams = {};
|
3756 | swiper.modules.forEach(mod => {
|
3757 | mod({
|
3758 | params,
|
3759 | swiper,
|
3760 | extendParams: moduleExtendParams(params, allModulesParams),
|
3761 | on: swiper.on.bind(swiper),
|
3762 | once: swiper.once.bind(swiper),
|
3763 | off: swiper.off.bind(swiper),
|
3764 | emit: swiper.emit.bind(swiper)
|
3765 | });
|
3766 | });
|
3767 |
|
3768 |
|
3769 | const swiperParams = extend$1({}, defaults, allModulesParams);
|
3770 |
|
3771 |
|
3772 | swiper.params = extend$1({}, swiperParams, extendedDefaults, params);
|
3773 | swiper.originalParams = extend$1({}, swiper.params);
|
3774 | swiper.passedParams = extend$1({}, params);
|
3775 |
|
3776 |
|
3777 | if (swiper.params && swiper.params.on) {
|
3778 | Object.keys(swiper.params.on).forEach(eventName => {
|
3779 | swiper.on(eventName, swiper.params.on[eventName]);
|
3780 | });
|
3781 | }
|
3782 | if (swiper.params && swiper.params.onAny) {
|
3783 | swiper.onAny(swiper.params.onAny);
|
3784 | }
|
3785 |
|
3786 |
|
3787 | Object.assign(swiper, {
|
3788 | enabled: swiper.params.enabled,
|
3789 | el,
|
3790 |
|
3791 | classNames: [],
|
3792 |
|
3793 | slides: [],
|
3794 | slidesGrid: [],
|
3795 | snapGrid: [],
|
3796 | slidesSizesGrid: [],
|
3797 |
|
3798 | isHorizontal() {
|
3799 | return swiper.params.direction === 'horizontal';
|
3800 | },
|
3801 | isVertical() {
|
3802 | return swiper.params.direction === 'vertical';
|
3803 | },
|
3804 |
|
3805 | activeIndex: 0,
|
3806 | realIndex: 0,
|
3807 |
|
3808 | isBeginning: true,
|
3809 | isEnd: false,
|
3810 |
|
3811 | translate: 0,
|
3812 | previousTranslate: 0,
|
3813 | progress: 0,
|
3814 | velocity: 0,
|
3815 | animating: false,
|
3816 | cssOverflowAdjustment() {
|
3817 |
|
3818 |
|
3819 | return Math.trunc(this.translate / 2 ** 23) * 2 ** 23;
|
3820 | },
|
3821 |
|
3822 | allowSlideNext: swiper.params.allowSlideNext,
|
3823 | allowSlidePrev: swiper.params.allowSlidePrev,
|
3824 |
|
3825 | touchEventsData: {
|
3826 | isTouched: undefined,
|
3827 | isMoved: undefined,
|
3828 | allowTouchCallbacks: undefined,
|
3829 | touchStartTime: undefined,
|
3830 | isScrolling: undefined,
|
3831 | currentTranslate: undefined,
|
3832 | startTranslate: undefined,
|
3833 | allowThresholdMove: undefined,
|
3834 |
|
3835 | focusableElements: swiper.params.focusableElements,
|
3836 |
|
3837 | lastClickTime: 0,
|
3838 | clickTimeout: undefined,
|
3839 |
|
3840 | velocities: [],
|
3841 | allowMomentumBounce: undefined,
|
3842 | startMoving: undefined,
|
3843 | pointerId: null,
|
3844 | touchId: null
|
3845 | },
|
3846 |
|
3847 | allowClick: true,
|
3848 |
|
3849 | allowTouchMove: swiper.params.allowTouchMove,
|
3850 | touches: {
|
3851 | startX: 0,
|
3852 | startY: 0,
|
3853 | currentX: 0,
|
3854 | currentY: 0,
|
3855 | diff: 0
|
3856 | },
|
3857 |
|
3858 | imagesToLoad: [],
|
3859 | imagesLoaded: 0
|
3860 | });
|
3861 | swiper.emit('_swiper');
|
3862 |
|
3863 |
|
3864 | if (swiper.params.init) {
|
3865 | swiper.init();
|
3866 | }
|
3867 |
|
3868 |
|
3869 |
|
3870 | return swiper;
|
3871 | }
|
3872 | getDirectionLabel(property) {
|
3873 | if (this.isHorizontal()) {
|
3874 | return property;
|
3875 | }
|
3876 |
|
3877 | return {
|
3878 | 'width': 'height',
|
3879 | 'margin-top': 'margin-left',
|
3880 | 'margin-bottom ': 'margin-right',
|
3881 | 'margin-left': 'margin-top',
|
3882 | 'margin-right': 'margin-bottom',
|
3883 | 'padding-left': 'padding-top',
|
3884 | 'padding-right': 'padding-bottom',
|
3885 | 'marginRight': 'marginBottom'
|
3886 | }[property];
|
3887 | }
|
3888 | getSlideIndex(slideEl) {
|
3889 | const {
|
3890 | slidesEl,
|
3891 | params
|
3892 | } = this;
|
3893 | const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
|
3894 | const firstSlideIndex = elementIndex(slides[0]);
|
3895 | return elementIndex(slideEl) - firstSlideIndex;
|
3896 | }
|
3897 | getSlideIndexByData(index) {
|
3898 | return this.getSlideIndex(this.slides.filter(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === index)[0]);
|
3899 | }
|
3900 | recalcSlides() {
|
3901 | const swiper = this;
|
3902 | const {
|
3903 | slidesEl,
|
3904 | params
|
3905 | } = swiper;
|
3906 | swiper.slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
|
3907 | }
|
3908 | enable() {
|
3909 | const swiper = this;
|
3910 | if (swiper.enabled) return;
|
3911 | swiper.enabled = true;
|
3912 | if (swiper.params.grabCursor) {
|
3913 | swiper.setGrabCursor();
|
3914 | }
|
3915 | swiper.emit('enable');
|
3916 | }
|
3917 | disable() {
|
3918 | const swiper = this;
|
3919 | if (!swiper.enabled) return;
|
3920 | swiper.enabled = false;
|
3921 | if (swiper.params.grabCursor) {
|
3922 | swiper.unsetGrabCursor();
|
3923 | }
|
3924 | swiper.emit('disable');
|
3925 | }
|
3926 | setProgress(progress, speed) {
|
3927 | const swiper = this;
|
3928 | progress = Math.min(Math.max(progress, 0), 1);
|
3929 | const min = swiper.minTranslate();
|
3930 | const max = swiper.maxTranslate();
|
3931 | const current = (max - min) * progress + min;
|
3932 | swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed);
|
3933 | swiper.updateActiveIndex();
|
3934 | swiper.updateSlidesClasses();
|
3935 | }
|
3936 | emitContainerClasses() {
|
3937 | const swiper = this;
|
3938 | if (!swiper.params._emitClasses || !swiper.el) return;
|
3939 | const cls = swiper.el.className.split(' ').filter(className => {
|
3940 | return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0;
|
3941 | });
|
3942 | swiper.emit('_containerClasses', cls.join(' '));
|
3943 | }
|
3944 | getSlideClasses(slideEl) {
|
3945 | const swiper = this;
|
3946 | if (swiper.destroyed) return '';
|
3947 | return slideEl.className.split(' ').filter(className => {
|
3948 | return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0;
|
3949 | }).join(' ');
|
3950 | }
|
3951 | emitSlidesClasses() {
|
3952 | const swiper = this;
|
3953 | if (!swiper.params._emitClasses || !swiper.el) return;
|
3954 | const updates = [];
|
3955 | swiper.slides.forEach(slideEl => {
|
3956 | const classNames = swiper.getSlideClasses(slideEl);
|
3957 | updates.push({
|
3958 | slideEl,
|
3959 | classNames
|
3960 | });
|
3961 | swiper.emit('_slideClass', slideEl, classNames);
|
3962 | });
|
3963 | swiper.emit('_slideClasses', updates);
|
3964 | }
|
3965 | slidesPerViewDynamic(view, exact) {
|
3966 | if (view === void 0) {
|
3967 | view = 'current';
|
3968 | }
|
3969 | if (exact === void 0) {
|
3970 | exact = false;
|
3971 | }
|
3972 | const swiper = this;
|
3973 | const {
|
3974 | params,
|
3975 | slides,
|
3976 | slidesGrid,
|
3977 | slidesSizesGrid,
|
3978 | size: swiperSize,
|
3979 | activeIndex
|
3980 | } = swiper;
|
3981 | let spv = 1;
|
3982 | if (typeof params.slidesPerView === 'number') return params.slidesPerView;
|
3983 | if (params.centeredSlides) {
|
3984 | let slideSize = slides[activeIndex] ? Math.ceil(slides[activeIndex].swiperSlideSize) : 0;
|
3985 | let breakLoop;
|
3986 | for (let i = activeIndex + 1; i < slides.length; i += 1) {
|
3987 | if (slides[i] && !breakLoop) {
|
3988 | slideSize += Math.ceil(slides[i].swiperSlideSize);
|
3989 | spv += 1;
|
3990 | if (slideSize > swiperSize) breakLoop = true;
|
3991 | }
|
3992 | }
|
3993 | for (let i = activeIndex - 1; i >= 0; i -= 1) {
|
3994 | if (slides[i] && !breakLoop) {
|
3995 | slideSize += slides[i].swiperSlideSize;
|
3996 | spv += 1;
|
3997 | if (slideSize > swiperSize) breakLoop = true;
|
3998 | }
|
3999 | }
|
4000 | } else {
|
4001 |
|
4002 | if (view === 'current') {
|
4003 | for (let i = activeIndex + 1; i < slides.length; i += 1) {
|
4004 | const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize;
|
4005 | if (slideInView) {
|
4006 | spv += 1;
|
4007 | }
|
4008 | }
|
4009 | } else {
|
4010 |
|
4011 | for (let i = activeIndex - 1; i >= 0; i -= 1) {
|
4012 | const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize;
|
4013 | if (slideInView) {
|
4014 | spv += 1;
|
4015 | }
|
4016 | }
|
4017 | }
|
4018 | }
|
4019 | return spv;
|
4020 | }
|
4021 | update() {
|
4022 | const swiper = this;
|
4023 | if (!swiper || swiper.destroyed) return;
|
4024 | const {
|
4025 | snapGrid,
|
4026 | params
|
4027 | } = swiper;
|
4028 |
|
4029 | if (params.breakpoints) {
|
4030 | swiper.setBreakpoint();
|
4031 | }
|
4032 | [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => {
|
4033 | if (imageEl.complete) {
|
4034 | processLazyPreloader(swiper, imageEl);
|
4035 | }
|
4036 | });
|
4037 | swiper.updateSize();
|
4038 | swiper.updateSlides();
|
4039 | swiper.updateProgress();
|
4040 | swiper.updateSlidesClasses();
|
4041 | function setTranslate() {
|
4042 | const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
|
4043 | const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
|
4044 | swiper.setTranslate(newTranslate);
|
4045 | swiper.updateActiveIndex();
|
4046 | swiper.updateSlidesClasses();
|
4047 | }
|
4048 | let translated;
|
4049 | if (params.freeMode && params.freeMode.enabled && !params.cssMode) {
|
4050 | setTranslate();
|
4051 | if (params.autoHeight) {
|
4052 | swiper.updateAutoHeight();
|
4053 | }
|
4054 | } else {
|
4055 | if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !params.centeredSlides) {
|
4056 | const slides = swiper.virtual && params.virtual.enabled ? swiper.virtual.slides : swiper.slides;
|
4057 | translated = swiper.slideTo(slides.length - 1, 0, false, true);
|
4058 | } else {
|
4059 | translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
|
4060 | }
|
4061 | if (!translated) {
|
4062 | setTranslate();
|
4063 | }
|
4064 | }
|
4065 | if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
|
4066 | swiper.checkOverflow();
|
4067 | }
|
4068 | swiper.emit('update');
|
4069 | }
|
4070 | changeDirection(newDirection, needUpdate) {
|
4071 | if (needUpdate === void 0) {
|
4072 | needUpdate = true;
|
4073 | }
|
4074 | const swiper = this;
|
4075 | const currentDirection = swiper.params.direction;
|
4076 | if (!newDirection) {
|
4077 |
|
4078 | newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
|
4079 | }
|
4080 | if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') {
|
4081 | return swiper;
|
4082 | }
|
4083 | swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`);
|
4084 | swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`);
|
4085 | swiper.emitContainerClasses();
|
4086 | swiper.params.direction = newDirection;
|
4087 | swiper.slides.forEach(slideEl => {
|
4088 | if (newDirection === 'vertical') {
|
4089 | slideEl.style.width = '';
|
4090 | } else {
|
4091 | slideEl.style.height = '';
|
4092 | }
|
4093 | });
|
4094 | swiper.emit('changeDirection');
|
4095 | if (needUpdate) swiper.update();
|
4096 | return swiper;
|
4097 | }
|
4098 | changeLanguageDirection(direction) {
|
4099 | const swiper = this;
|
4100 | if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return;
|
4101 | swiper.rtl = direction === 'rtl';
|
4102 | swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl;
|
4103 | if (swiper.rtl) {
|
4104 | swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`);
|
4105 | swiper.el.dir = 'rtl';
|
4106 | } else {
|
4107 | swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`);
|
4108 | swiper.el.dir = 'ltr';
|
4109 | }
|
4110 | swiper.update();
|
4111 | }
|
4112 | mount(element) {
|
4113 | const swiper = this;
|
4114 | if (swiper.mounted) return true;
|
4115 |
|
4116 |
|
4117 | let el = element || swiper.params.el;
|
4118 | if (typeof el === 'string') {
|
4119 | el = document.querySelector(el);
|
4120 | }
|
4121 | if (!el) {
|
4122 | return false;
|
4123 | }
|
4124 | el.swiper = swiper;
|
4125 | if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === swiper.params.swiperElementNodeName.toUpperCase()) {
|
4126 | swiper.isElement = true;
|
4127 | }
|
4128 | const getWrapperSelector = () => {
|
4129 | return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`;
|
4130 | };
|
4131 | const getWrapper = () => {
|
4132 | if (el && el.shadowRoot && el.shadowRoot.querySelector) {
|
4133 | const res = el.shadowRoot.querySelector(getWrapperSelector());
|
4134 |
|
4135 | return res;
|
4136 | }
|
4137 | return elementChildren(el, getWrapperSelector())[0];
|
4138 | };
|
4139 |
|
4140 | let wrapperEl = getWrapper();
|
4141 | if (!wrapperEl && swiper.params.createElements) {
|
4142 | wrapperEl = createElement('div', swiper.params.wrapperClass);
|
4143 | el.append(wrapperEl);
|
4144 | elementChildren(el, `.${swiper.params.slideClass}`).forEach(slideEl => {
|
4145 | wrapperEl.append(slideEl);
|
4146 | });
|
4147 | }
|
4148 | Object.assign(swiper, {
|
4149 | el,
|
4150 | wrapperEl,
|
4151 | slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
|
4152 | hostEl: swiper.isElement ? el.parentNode.host : el,
|
4153 | mounted: true,
|
4154 |
|
4155 | rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
|
4156 | rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
|
4157 | wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
|
4158 | });
|
4159 | return true;
|
4160 | }
|
4161 | init(el) {
|
4162 | const swiper = this;
|
4163 | if (swiper.initialized) return swiper;
|
4164 | const mounted = swiper.mount(el);
|
4165 | if (mounted === false) return swiper;
|
4166 | swiper.emit('beforeInit');
|
4167 |
|
4168 |
|
4169 | if (swiper.params.breakpoints) {
|
4170 | swiper.setBreakpoint();
|
4171 | }
|
4172 |
|
4173 |
|
4174 | swiper.addClasses();
|
4175 |
|
4176 |
|
4177 | swiper.updateSize();
|
4178 |
|
4179 |
|
4180 | swiper.updateSlides();
|
4181 | if (swiper.params.watchOverflow) {
|
4182 | swiper.checkOverflow();
|
4183 | }
|
4184 |
|
4185 |
|
4186 | if (swiper.params.grabCursor && swiper.enabled) {
|
4187 | swiper.setGrabCursor();
|
4188 | }
|
4189 |
|
4190 |
|
4191 | if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
|
4192 | swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true);
|
4193 | } else {
|
4194 | swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true);
|
4195 | }
|
4196 |
|
4197 |
|
4198 | if (swiper.params.loop) {
|
4199 | swiper.loopCreate();
|
4200 | }
|
4201 |
|
4202 |
|
4203 | swiper.attachEvents();
|
4204 | const lazyElements = [...swiper.el.querySelectorAll('[loading="lazy"]')];
|
4205 | if (swiper.isElement) {
|
4206 | lazyElements.push(...swiper.hostEl.querySelectorAll('[loading="lazy"]'));
|
4207 | }
|
4208 | lazyElements.forEach(imageEl => {
|
4209 | if (imageEl.complete) {
|
4210 | processLazyPreloader(swiper, imageEl);
|
4211 | } else {
|
4212 | imageEl.addEventListener('load', e => {
|
4213 | processLazyPreloader(swiper, e.target);
|
4214 | });
|
4215 | }
|
4216 | });
|
4217 | preload(swiper);
|
4218 |
|
4219 |
|
4220 | swiper.initialized = true;
|
4221 | preload(swiper);
|
4222 |
|
4223 |
|
4224 | swiper.emit('init');
|
4225 | swiper.emit('afterInit');
|
4226 | return swiper;
|
4227 | }
|
4228 | destroy(deleteInstance, cleanStyles) {
|
4229 | if (deleteInstance === void 0) {
|
4230 | deleteInstance = true;
|
4231 | }
|
4232 | if (cleanStyles === void 0) {
|
4233 | cleanStyles = true;
|
4234 | }
|
4235 | const swiper = this;
|
4236 | const {
|
4237 | params,
|
4238 | el,
|
4239 | wrapperEl,
|
4240 | slides
|
4241 | } = swiper;
|
4242 | if (typeof swiper.params === 'undefined' || swiper.destroyed) {
|
4243 | return null;
|
4244 | }
|
4245 | swiper.emit('beforeDestroy');
|
4246 |
|
4247 |
|
4248 | swiper.initialized = false;
|
4249 |
|
4250 |
|
4251 | swiper.detachEvents();
|
4252 |
|
4253 |
|
4254 | if (params.loop) {
|
4255 | swiper.loopDestroy();
|
4256 | }
|
4257 |
|
4258 |
|
4259 | if (cleanStyles) {
|
4260 | swiper.removeClasses();
|
4261 | if (el && typeof el !== 'string') {
|
4262 | el.removeAttribute('style');
|
4263 | }
|
4264 | if (wrapperEl) {
|
4265 | wrapperEl.removeAttribute('style');
|
4266 | }
|
4267 | if (slides && slides.length) {
|
4268 | slides.forEach(slideEl => {
|
4269 | slideEl.classList.remove(params.slideVisibleClass, params.slideFullyVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass);
|
4270 | slideEl.removeAttribute('style');
|
4271 | slideEl.removeAttribute('data-swiper-slide-index');
|
4272 | });
|
4273 | }
|
4274 | }
|
4275 | swiper.emit('destroy');
|
4276 |
|
4277 |
|
4278 | Object.keys(swiper.eventsListeners).forEach(eventName => {
|
4279 | swiper.off(eventName);
|
4280 | });
|
4281 | if (deleteInstance !== false) {
|
4282 | if (swiper.el && typeof swiper.el !== 'string') {
|
4283 | swiper.el.swiper = null;
|
4284 | }
|
4285 | deleteProps(swiper);
|
4286 | }
|
4287 | swiper.destroyed = true;
|
4288 | return null;
|
4289 | }
|
4290 | static extendDefaults(newDefaults) {
|
4291 | extend$1(extendedDefaults, newDefaults);
|
4292 | }
|
4293 | static get extendedDefaults() {
|
4294 | return extendedDefaults;
|
4295 | }
|
4296 | static get defaults() {
|
4297 | return defaults;
|
4298 | }
|
4299 | static installModule(mod) {
|
4300 | if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = [];
|
4301 | const modules = Swiper.prototype.__modules__;
|
4302 | if (typeof mod === 'function' && modules.indexOf(mod) < 0) {
|
4303 | modules.push(mod);
|
4304 | }
|
4305 | }
|
4306 | static use(module) {
|
4307 | if (Array.isArray(module)) {
|
4308 | module.forEach(m => Swiper.installModule(m));
|
4309 | return Swiper;
|
4310 | }
|
4311 | Swiper.installModule(module);
|
4312 | return Swiper;
|
4313 | }
|
4314 | }
|
4315 | Object.keys(prototypes).forEach(prototypeGroup => {
|
4316 | Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => {
|
4317 | Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
|
4318 | });
|
4319 | });
|
4320 | Swiper.use([Resize, Observer]);
|
4321 |
|
4322 |
|
4323 | const paramsList = ['eventsPrefix', 'injectStyles', 'injectStylesUrls', 'modules', 'init', '_direction', 'oneWayMovement', 'swiperElementNodeName', 'touchEventsTarget', 'initialSlide', '_speed', 'cssMode', 'updateOnWindowResize', 'resizeObserver', 'nested', 'focusableElements', '_enabled', '_width', '_height', 'preventInteractionOnTransition', 'userAgent', 'url', '_edgeSwipeDetection', '_edgeSwipeThreshold', '_freeMode', '_autoHeight', 'setWrapperSize', 'virtualTranslate', '_effect', 'breakpoints', 'breakpointsBase', '_spaceBetween', '_slidesPerView', 'maxBackfaceHiddenSlides', '_grid', '_slidesPerGroup', '_slidesPerGroupSkip', '_slidesPerGroupAuto', '_centeredSlides', '_centeredSlidesBounds', '_slidesOffsetBefore', '_slidesOffsetAfter', 'normalizeSlideIndex', '_centerInsufficientSlides', '_watchOverflow', 'roundLengths', 'touchRatio', 'touchAngle', 'simulateTouch', '_shortSwipes', '_longSwipes', 'longSwipesRatio', 'longSwipesMs', '_followFinger', 'allowTouchMove', '_threshold', 'touchMoveStopPropagation', 'touchStartPreventDefault', 'touchStartForcePreventDefault', 'touchReleaseOnEdges', 'uniqueNavElements', '_resistance', '_resistanceRatio', '_watchSlidesProgress', '_grabCursor', 'preventClicks', 'preventClicksPropagation', '_slideToClickedSlide', '_loop', 'loopAdditionalSlides', 'loopAddBlankSlides', 'loopPreventsSliding', '_rewind', '_allowSlidePrev', '_allowSlideNext', '_swipeHandler', '_noSwiping', 'noSwipingClass', 'noSwipingSelector', 'passiveListeners', 'containerModifierClass', 'slideClass', 'slideActiveClass', 'slideVisibleClass', 'slideFullyVisibleClass', 'slideNextClass', 'slidePrevClass', 'slideBlankClass', 'wrapperClass', 'lazyPreloaderClass', 'lazyPreloadPrevNext', 'runCallbacksOnInit', 'observer', 'observeParents', 'observeSlideChildren',
|
4324 |
|
4325 | 'a11y', '_autoplay', '_controller', 'coverflowEffect', 'cubeEffect', 'fadeEffect', 'flipEffect', 'creativeEffect', 'cardsEffect', 'hashNavigation', 'history', 'keyboard', 'mousewheel', '_navigation', '_pagination', 'parallax', '_scrollbar', '_thumbs', 'virtual', 'zoom', 'control'];
|
4326 |
|
4327 | function isObject(o) {
|
4328 | return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object' && !o.__swiper__;
|
4329 | }
|
4330 | function extend(target, src) {
|
4331 | const noExtend = ['__proto__', 'constructor', 'prototype'];
|
4332 | Object.keys(src).filter(key => noExtend.indexOf(key) < 0).forEach(key => {
|
4333 | if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) {
|
4334 | if (src[key].__swiper__) target[key] = src[key];else extend(target[key], src[key]);
|
4335 | } else {
|
4336 | target[key] = src[key];
|
4337 | }
|
4338 | });
|
4339 | }
|
4340 | function needsNavigation(params) {
|
4341 | if (params === void 0) {
|
4342 | params = {};
|
4343 | }
|
4344 | return params.navigation && typeof params.navigation.nextEl === 'undefined' && typeof params.navigation.prevEl === 'undefined';
|
4345 | }
|
4346 | function needsPagination(params) {
|
4347 | if (params === void 0) {
|
4348 | params = {};
|
4349 | }
|
4350 | return params.pagination && typeof params.pagination.el === 'undefined';
|
4351 | }
|
4352 | function needsScrollbar(params) {
|
4353 | if (params === void 0) {
|
4354 | params = {};
|
4355 | }
|
4356 | return params.scrollbar && typeof params.scrollbar.el === 'undefined';
|
4357 | }
|
4358 | function attrToProp(attrName) {
|
4359 | if (attrName === void 0) {
|
4360 | attrName = '';
|
4361 | }
|
4362 | return attrName.replace(/-[a-z]/g, l => l.toUpperCase().replace('-', ''));
|
4363 | }
|
4364 |
|
4365 | function updateSwiper(_ref) {
|
4366 | let {
|
4367 | swiper,
|
4368 | slides,
|
4369 | passedParams,
|
4370 | changedParams,
|
4371 | nextEl,
|
4372 | prevEl,
|
4373 | scrollbarEl,
|
4374 | paginationEl
|
4375 | } = _ref;
|
4376 | const updateParams = changedParams.filter(key => key !== 'children' && key !== 'direction' && key !== 'wrapperClass');
|
4377 | const {
|
4378 | params: currentParams,
|
4379 | pagination,
|
4380 | navigation,
|
4381 | scrollbar,
|
4382 | virtual,
|
4383 | thumbs
|
4384 | } = swiper;
|
4385 | let needThumbsInit;
|
4386 | let needControllerInit;
|
4387 | let needPaginationInit;
|
4388 | let needScrollbarInit;
|
4389 | let needNavigationInit;
|
4390 | let loopNeedDestroy;
|
4391 | let loopNeedEnable;
|
4392 | let loopNeedReloop;
|
4393 | if (changedParams.includes('thumbs') && passedParams.thumbs && passedParams.thumbs.swiper && currentParams.thumbs && !currentParams.thumbs.swiper) {
|
4394 | needThumbsInit = true;
|
4395 | }
|
4396 | if (changedParams.includes('controller') && passedParams.controller && passedParams.controller.control && currentParams.controller && !currentParams.controller.control) {
|
4397 | needControllerInit = true;
|
4398 | }
|
4399 | if (changedParams.includes('pagination') && passedParams.pagination && (passedParams.pagination.el || paginationEl) && (currentParams.pagination || currentParams.pagination === false) && pagination && !pagination.el) {
|
4400 | needPaginationInit = true;
|
4401 | }
|
4402 | if (changedParams.includes('scrollbar') && passedParams.scrollbar && (passedParams.scrollbar.el || scrollbarEl) && (currentParams.scrollbar || currentParams.scrollbar === false) && scrollbar && !scrollbar.el) {
|
4403 | needScrollbarInit = true;
|
4404 | }
|
4405 | if (changedParams.includes('navigation') && passedParams.navigation && (passedParams.navigation.prevEl || prevEl) && (passedParams.navigation.nextEl || nextEl) && (currentParams.navigation || currentParams.navigation === false) && navigation && !navigation.prevEl && !navigation.nextEl) {
|
4406 | needNavigationInit = true;
|
4407 | }
|
4408 | const destroyModule = mod => {
|
4409 | if (!swiper[mod]) return;
|
4410 | swiper[mod].destroy();
|
4411 | if (mod === 'navigation') {
|
4412 | if (swiper.isElement) {
|
4413 | swiper[mod].prevEl.remove();
|
4414 | swiper[mod].nextEl.remove();
|
4415 | }
|
4416 | currentParams[mod].prevEl = undefined;
|
4417 | currentParams[mod].nextEl = undefined;
|
4418 | swiper[mod].prevEl = undefined;
|
4419 | swiper[mod].nextEl = undefined;
|
4420 | } else {
|
4421 | if (swiper.isElement) {
|
4422 | swiper[mod].el.remove();
|
4423 | }
|
4424 | currentParams[mod].el = undefined;
|
4425 | swiper[mod].el = undefined;
|
4426 | }
|
4427 | };
|
4428 | if (changedParams.includes('loop') && swiper.isElement) {
|
4429 | if (currentParams.loop && !passedParams.loop) {
|
4430 | loopNeedDestroy = true;
|
4431 | } else if (!currentParams.loop && passedParams.loop) {
|
4432 | loopNeedEnable = true;
|
4433 | } else {
|
4434 | loopNeedReloop = true;
|
4435 | }
|
4436 | }
|
4437 | updateParams.forEach(key => {
|
4438 | if (isObject(currentParams[key]) && isObject(passedParams[key])) {
|
4439 | Object.assign(currentParams[key], passedParams[key]);
|
4440 | if ((key === 'navigation' || key === 'pagination' || key === 'scrollbar') && 'enabled' in passedParams[key] && !passedParams[key].enabled) {
|
4441 | destroyModule(key);
|
4442 | }
|
4443 | } else {
|
4444 | const newValue = passedParams[key];
|
4445 | if ((newValue === true || newValue === false) && (key === 'navigation' || key === 'pagination' || key === 'scrollbar')) {
|
4446 | if (newValue === false) {
|
4447 | destroyModule(key);
|
4448 | }
|
4449 | } else {
|
4450 | currentParams[key] = passedParams[key];
|
4451 | }
|
4452 | }
|
4453 | });
|
4454 | if (updateParams.includes('controller') && !needControllerInit && swiper.controller && swiper.controller.control && currentParams.controller && currentParams.controller.control) {
|
4455 | swiper.controller.control = currentParams.controller.control;
|
4456 | }
|
4457 | if (changedParams.includes('children') && slides && virtual && currentParams.virtual.enabled) {
|
4458 | virtual.slides = slides;
|
4459 | virtual.update(true);
|
4460 | } else if (changedParams.includes('virtual') && virtual && currentParams.virtual.enabled) {
|
4461 | if (slides) virtual.slides = slides;
|
4462 | virtual.update(true);
|
4463 | }
|
4464 | if (changedParams.includes('children') && slides && currentParams.loop) {
|
4465 | loopNeedReloop = true;
|
4466 | }
|
4467 | if (needThumbsInit) {
|
4468 | const initialized = thumbs.init();
|
4469 | if (initialized) thumbs.update(true);
|
4470 | }
|
4471 | if (needControllerInit) {
|
4472 | swiper.controller.control = currentParams.controller.control;
|
4473 | }
|
4474 | if (needPaginationInit) {
|
4475 | if (swiper.isElement && (!paginationEl || typeof paginationEl === 'string')) {
|
4476 | paginationEl = document.createElement('div');
|
4477 | paginationEl.classList.add('swiper-pagination');
|
4478 | paginationEl.part.add('pagination');
|
4479 | swiper.el.appendChild(paginationEl);
|
4480 | }
|
4481 | if (paginationEl) currentParams.pagination.el = paginationEl;
|
4482 | pagination.init();
|
4483 | pagination.render();
|
4484 | pagination.update();
|
4485 | }
|
4486 | if (needScrollbarInit) {
|
4487 | if (swiper.isElement && (!scrollbarEl || typeof scrollbarEl === 'string')) {
|
4488 | scrollbarEl = document.createElement('div');
|
4489 | scrollbarEl.classList.add('swiper-scrollbar');
|
4490 | scrollbarEl.part.add('scrollbar');
|
4491 | swiper.el.appendChild(scrollbarEl);
|
4492 | }
|
4493 | if (scrollbarEl) currentParams.scrollbar.el = scrollbarEl;
|
4494 | scrollbar.init();
|
4495 | scrollbar.updateSize();
|
4496 | scrollbar.setTranslate();
|
4497 | }
|
4498 | if (needNavigationInit) {
|
4499 | if (swiper.isElement) {
|
4500 | if (!nextEl || typeof nextEl === 'string') {
|
4501 | nextEl = document.createElement('div');
|
4502 | nextEl.classList.add('swiper-button-next');
|
4503 | nextEl.innerHTML = swiper.hostEl.constructor.nextButtonSvg;
|
4504 | nextEl.part.add('button-next');
|
4505 | swiper.el.appendChild(nextEl);
|
4506 | }
|
4507 | if (!prevEl || typeof prevEl === 'string') {
|
4508 | prevEl = document.createElement('div');
|
4509 | prevEl.classList.add('swiper-button-prev');
|
4510 | prevEl.innerHTML = swiper.hostEl.constructor.prevButtonSvg;
|
4511 | prevEl.part.add('button-prev');
|
4512 | swiper.el.appendChild(prevEl);
|
4513 | }
|
4514 | }
|
4515 | if (nextEl) currentParams.navigation.nextEl = nextEl;
|
4516 | if (prevEl) currentParams.navigation.prevEl = prevEl;
|
4517 | navigation.init();
|
4518 | navigation.update();
|
4519 | }
|
4520 | if (changedParams.includes('allowSlideNext')) {
|
4521 | swiper.allowSlideNext = passedParams.allowSlideNext;
|
4522 | }
|
4523 | if (changedParams.includes('allowSlidePrev')) {
|
4524 | swiper.allowSlidePrev = passedParams.allowSlidePrev;
|
4525 | }
|
4526 | if (changedParams.includes('direction')) {
|
4527 | swiper.changeDirection(passedParams.direction, false);
|
4528 | }
|
4529 | if (loopNeedDestroy || loopNeedReloop) {
|
4530 | swiper.loopDestroy();
|
4531 | }
|
4532 | if (loopNeedEnable || loopNeedReloop) {
|
4533 | swiper.loopCreate();
|
4534 | }
|
4535 | swiper.update();
|
4536 | }
|
4537 |
|
4538 | const formatValue = val => {
|
4539 | if (parseFloat(val) === Number(val)) return Number(val);
|
4540 | if (val === 'true') return true;
|
4541 | if (val === '') return true;
|
4542 | if (val === 'false') return false;
|
4543 | if (val === 'null') return null;
|
4544 | if (val === 'undefined') return undefined;
|
4545 | if (typeof val === 'string' && val.includes('{') && val.includes('}') && val.includes('"')) {
|
4546 | let v;
|
4547 | try {
|
4548 | v = JSON.parse(val);
|
4549 | } catch (err) {
|
4550 | v = val;
|
4551 | }
|
4552 | return v;
|
4553 | }
|
4554 | return val;
|
4555 | };
|
4556 | const modulesParamsList = ['a11y', 'autoplay', 'controller', 'cards-effect', 'coverflow-effect', 'creative-effect', 'cube-effect', 'fade-effect', 'flip-effect', 'free-mode', 'grid', 'hash-navigation', 'history', 'keyboard', 'mousewheel', 'navigation', 'pagination', 'parallax', 'scrollbar', 'thumbs', 'virtual', 'zoom'];
|
4557 | function getParams(element, propName, propValue) {
|
4558 | const params = {};
|
4559 | const passedParams = {};
|
4560 | extend(params, defaults);
|
4561 | const localParamsList = [...paramsList, 'on'];
|
4562 | const allowedParams = localParamsList.map(key => key.replace(/_/, ''));
|
4563 |
|
4564 |
|
4565 | localParamsList.forEach(paramName => {
|
4566 | paramName = paramName.replace('_', '');
|
4567 | if (typeof element[paramName] !== 'undefined') {
|
4568 | passedParams[paramName] = element[paramName];
|
4569 | }
|
4570 | });
|
4571 |
|
4572 |
|
4573 | const attrsList = [...element.attributes];
|
4574 | if (typeof propName === 'string' && typeof propValue !== 'undefined') {
|
4575 | attrsList.push({
|
4576 | name: propName,
|
4577 | value: isObject(propValue) ? {
|
4578 | ...propValue
|
4579 | } : propValue
|
4580 | });
|
4581 | }
|
4582 | attrsList.forEach(attr => {
|
4583 | const moduleParam = modulesParamsList.filter(mParam => attr.name.indexOf(`${mParam}-`) === 0)[0];
|
4584 | if (moduleParam) {
|
4585 | const parentObjName = attrToProp(moduleParam);
|
4586 | const subObjName = attrToProp(attr.name.split(`${moduleParam}-`)[1]);
|
4587 | if (typeof passedParams[parentObjName] === 'undefined') passedParams[parentObjName] = {};
|
4588 | if (passedParams[parentObjName] === true) {
|
4589 | passedParams[parentObjName] = {
|
4590 | enabled: true
|
4591 | };
|
4592 | }
|
4593 | passedParams[parentObjName][subObjName] = formatValue(attr.value);
|
4594 | } else {
|
4595 | const name = attrToProp(attr.name);
|
4596 | if (!allowedParams.includes(name)) return;
|
4597 | const value = formatValue(attr.value);
|
4598 | if (passedParams[name] && modulesParamsList.includes(attr.name) && !isObject(value)) {
|
4599 | if (passedParams[name].constructor !== Object) {
|
4600 | passedParams[name] = {};
|
4601 | }
|
4602 | passedParams[name].enabled = !!value;
|
4603 | } else {
|
4604 | passedParams[name] = value;
|
4605 | }
|
4606 | }
|
4607 | });
|
4608 | extend(params, passedParams);
|
4609 | if (params.navigation) {
|
4610 | params.navigation = {
|
4611 | prevEl: '.swiper-button-prev',
|
4612 | nextEl: '.swiper-button-next',
|
4613 | ...(params.navigation !== true ? params.navigation : {})
|
4614 | };
|
4615 | } else if (params.navigation === false) {
|
4616 | delete params.navigation;
|
4617 | }
|
4618 | if (params.scrollbar) {
|
4619 | params.scrollbar = {
|
4620 | el: '.swiper-scrollbar',
|
4621 | ...(params.scrollbar !== true ? params.scrollbar : {})
|
4622 | };
|
4623 | } else if (params.scrollbar === false) {
|
4624 | delete params.scrollbar;
|
4625 | }
|
4626 | if (params.pagination) {
|
4627 | params.pagination = {
|
4628 | el: '.swiper-pagination',
|
4629 | ...(params.pagination !== true ? params.pagination : {})
|
4630 | };
|
4631 | } else if (params.pagination === false) {
|
4632 | delete params.pagination;
|
4633 | }
|
4634 | return {
|
4635 | params,
|
4636 | passedParams
|
4637 | };
|
4638 | }
|
4639 |
|
4640 | |
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 | const SwiperCSS = `:host{--swiper-theme-color:#007aff}:host{position:relative;display:block;margin-left:auto;margin-right:auto;z-index:1}.swiper{width:100%;height:100%;margin-left:auto;margin-right:auto;position:relative;overflow:hidden;list-style:none;padding:0;z-index:1;display:block}.swiper-vertical>.swiper-wrapper{flex-direction:column}.swiper-wrapper{position:relative;width:100%;height:100%;z-index:1;display:flex;transition-property:transform;transition-timing-function:var(--swiper-wrapper-transition-timing-function,initial);box-sizing:content-box}.swiper-android ::slotted(swiper-slide),.swiper-ios ::slotted(swiper-slide),.swiper-wrapper{transform:translate3d(0px,0,0)}.swiper-horizontal{touch-action:pan-y}.swiper-vertical{touch-action:pan-x}::slotted(swiper-slide){flex-shrink:0;width:100%;height:100%;position:relative;transition-property:transform;display:block}::slotted(.swiper-slide-invisible-blank){visibility:hidden}.swiper-autoheight,.swiper-autoheight ::slotted(swiper-slide){height:auto}.swiper-autoheight .swiper-wrapper{align-items:flex-start;transition-property:transform,height}.swiper-backface-hidden ::slotted(swiper-slide){transform:translateZ(0);-webkit-backface-visibility:hidden;backface-visibility:hidden}.swiper-3d.swiper-css-mode .swiper-wrapper{perspective:1200px}.swiper-3d .swiper-wrapper{transform-style:preserve-3d}.swiper-3d{perspective:1200px}.swiper-3d .swiper-cube-shadow,.swiper-3d ::slotted(swiper-slide){transform-style:preserve-3d}.swiper-css-mode>.swiper-wrapper{overflow:auto;scrollbar-width:none;-ms-overflow-style:none}.swiper-css-mode>.swiper-wrapper::-webkit-scrollbar{display:none}.swiper-css-mode ::slotted(swiper-slide){scroll-snap-align:start start}.swiper-css-mode.swiper-horizontal>.swiper-wrapper{scroll-snap-type:x mandatory}.swiper-css-mode.swiper-vertical>.swiper-wrapper{scroll-snap-type:y mandatory}.swiper-css-mode.swiper-free-mode>.swiper-wrapper{scroll-snap-type:none}.swiper-css-mode.swiper-free-mode ::slotted(swiper-slide){scroll-snap-align:none}.swiper-css-mode.swiper-centered>.swiper-wrapper::before{content:'';flex-shrink:0;order:9999}.swiper-css-mode.swiper-centered ::slotted(swiper-slide){scroll-snap-align:center center;scroll-snap-stop:always}.swiper-css-mode.swiper-centered.swiper-horizontal ::slotted(swiper-slide):first-child{margin-inline-start:var(--swiper-centered-offset-before)}.swiper-css-mode.swiper-centered.swiper-horizontal>.swiper-wrapper::before{height:100%;min-height:1px;width:var(--swiper-centered-offset-after)}.swiper-css-mode.swiper-centered.swiper-vertical ::slotted(swiper-slide):first-child{margin-block-start:var(--swiper-centered-offset-before)}.swiper-css-mode.swiper-centered.swiper-vertical>.swiper-wrapper::before{width:100%;min-width:1px;height:var(--swiper-centered-offset-after)}`;
|
4656 | const SwiperSlideCSS = `::slotted(.swiper-slide-shadow),::slotted(.swiper-slide-shadow-bottom),::slotted(.swiper-slide-shadow-left),::slotted(.swiper-slide-shadow-right),::slotted(.swiper-slide-shadow-top){position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:10}::slotted(.swiper-slide-shadow){background:rgba(0,0,0,.15)}::slotted(.swiper-slide-shadow-left){background-image:linear-gradient(to left,rgba(0,0,0,.5),rgba(0,0,0,0))}::slotted(.swiper-slide-shadow-right){background-image:linear-gradient(to right,rgba(0,0,0,.5),rgba(0,0,0,0))}::slotted(.swiper-slide-shadow-top){background-image:linear-gradient(to top,rgba(0,0,0,.5),rgba(0,0,0,0))}::slotted(.swiper-slide-shadow-bottom){background-image:linear-gradient(to bottom,rgba(0,0,0,.5),rgba(0,0,0,0))}.swiper-lazy-preloader{animation:swiper-preloader-spin 1s infinite linear;width:42px;height:42px;position:absolute;left:50%;top:50%;margin-left:-21px;margin-top:-21px;z-index:10;transform-origin:50%;box-sizing:border-box;border:4px solid var(--swiper-preloader-color,var(--swiper-theme-color));border-radius:50%;border-top-color:transparent}@keyframes swiper-preloader-spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-bottom),::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-left),::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-right),::slotted(.swiper-slide-shadow-cube.swiper-slide-shadow-top){z-index:0;-webkit-backface-visibility:hidden;backface-visibility:hidden}::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-bottom),::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-left),::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-right),::slotted(.swiper-slide-shadow-flip.swiper-slide-shadow-top){z-index:0;-webkit-backface-visibility:hidden;backface-visibility:hidden}::slotted(.swiper-zoom-container){width:100%;height:100%;display:flex;justify-content:center;align-items:center;text-align:center}::slotted(.swiper-zoom-container)>canvas,::slotted(.swiper-zoom-container)>img,::slotted(.swiper-zoom-container)>svg{max-width:100%;max-height:100%;object-fit:contain}`;
|
4657 |
|
4658 | class DummyHTMLElement {}
|
4659 | const ClassToExtend = typeof window === 'undefined' || typeof HTMLElement === 'undefined' ? DummyHTMLElement : HTMLElement;
|
4660 | const arrowSvg = `<svg width="11" height="20" viewBox="0 0 11 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0.38296 20.0762C0.111788 19.805 0.111788 19.3654 0.38296 19.0942L9.19758 10.2796L0.38296 1.46497C0.111788 1.19379 0.111788 0.754138 0.38296 0.482966C0.654131 0.211794 1.09379 0.211794 1.36496 0.482966L10.4341 9.55214C10.8359 9.9539 10.8359 10.6053 10.4341 11.007L1.36496 20.0762C1.09379 20.3474 0.654131 20.3474 0.38296 20.0762Z" fill="currentColor"/></svg>
|
4661 | `;
|
4662 | const addStyle = (shadowRoot, styles) => {
|
4663 | if (typeof CSSStyleSheet !== 'undefined' && shadowRoot.adoptedStyleSheets) {
|
4664 | const styleSheet = new CSSStyleSheet();
|
4665 | styleSheet.replaceSync(styles);
|
4666 | shadowRoot.adoptedStyleSheets = [styleSheet];
|
4667 | } else {
|
4668 | const style = document.createElement('style');
|
4669 | style.rel = 'stylesheet';
|
4670 | style.textContent = styles;
|
4671 | shadowRoot.appendChild(style);
|
4672 | }
|
4673 | };
|
4674 | class SwiperContainer extends ClassToExtend {
|
4675 | constructor() {
|
4676 | super();
|
4677 | this.attachShadow({
|
4678 | mode: 'open'
|
4679 | });
|
4680 | }
|
4681 | static get nextButtonSvg() {
|
4682 | return arrowSvg;
|
4683 | }
|
4684 | static get prevButtonSvg() {
|
4685 | return arrowSvg.replace('/></svg>', ' transform-origin="center" transform="rotate(180)"/></svg>');
|
4686 | }
|
4687 | cssStyles() {
|
4688 | return [SwiperCSS,
|
4689 |
|
4690 | ...(this.injectStyles && Array.isArray(this.injectStyles) ? this.injectStyles : [])].join('\n');
|
4691 | }
|
4692 | cssLinks() {
|
4693 | return this.injectStylesUrls || [];
|
4694 | }
|
4695 | calcSlideSlots() {
|
4696 | const currentSideSlots = this.slideSlots || 0;
|
4697 |
|
4698 | const slideSlotChildren = [...this.querySelectorAll(`[slot^=slide-]`)].map(child => {
|
4699 | return parseInt(child.getAttribute('slot').split('slide-')[1], 10);
|
4700 | });
|
4701 | this.slideSlots = slideSlotChildren.length ? Math.max(...slideSlotChildren) + 1 : 0;
|
4702 | if (!this.rendered) return;
|
4703 | if (this.slideSlots > currentSideSlots) {
|
4704 | for (let i = currentSideSlots; i < this.slideSlots; i += 1) {
|
4705 | const slideEl = document.createElement('swiper-slide');
|
4706 | slideEl.setAttribute('part', `slide slide-${i + 1}`);
|
4707 | const slotEl = document.createElement('slot');
|
4708 | slotEl.setAttribute('name', `slide-${i + 1}`);
|
4709 | slideEl.appendChild(slotEl);
|
4710 | this.shadowRoot.querySelector('.swiper-wrapper').appendChild(slideEl);
|
4711 | }
|
4712 | } else if (this.slideSlots < currentSideSlots) {
|
4713 | const slides = this.swiper.slides;
|
4714 | for (let i = slides.length - 1; i >= 0; i -= 1) {
|
4715 | if (i > this.slideSlots) {
|
4716 | slides[i].remove();
|
4717 | }
|
4718 | }
|
4719 | }
|
4720 | }
|
4721 | render() {
|
4722 | if (this.rendered) return;
|
4723 | this.calcSlideSlots();
|
4724 |
|
4725 |
|
4726 | let localStyles = this.cssStyles();
|
4727 | if (this.slideSlots > 0) {
|
4728 | localStyles = localStyles.replace(/::slotted\(([a-z-0-9.]*)\)/g, '$1');
|
4729 | }
|
4730 | if (localStyles.length) {
|
4731 | addStyle(this.shadowRoot, localStyles);
|
4732 | }
|
4733 | this.cssLinks().forEach(url => {
|
4734 | const linkExists = this.shadowRoot.querySelector(`link[href="${url}"]`);
|
4735 | if (linkExists) return;
|
4736 | const linkEl = document.createElement('link');
|
4737 | linkEl.rel = 'stylesheet';
|
4738 | linkEl.href = url;
|
4739 | this.shadowRoot.appendChild(linkEl);
|
4740 | });
|
4741 |
|
4742 | const el = document.createElement('div');
|
4743 | el.classList.add('swiper');
|
4744 | el.part = 'container';
|
4745 |
|
4746 |
|
4747 | el.innerHTML = `
|
4748 | <slot name="container-start"></slot>
|
4749 | <div class="swiper-wrapper" part="wrapper">
|
4750 | <slot></slot>
|
4751 | ${Array.from({
|
4752 | length: this.slideSlots
|
4753 | }).map((_, index) => `
|
4754 | <swiper-slide part="slide slide-${index}">
|
4755 | <slot name="slide-${index}"></slot>
|
4756 | </swiper-slide>
|
4757 | `).join('')}
|
4758 | </div>
|
4759 | <slot name="container-end"></slot>
|
4760 | ${needsNavigation(this.passedParams) ? `
|
4761 | <div part="button-prev" class="swiper-button-prev">${this.constructor.prevButtonSvg}</div>
|
4762 | <div part="button-next" class="swiper-button-next">${this.constructor.nextButtonSvg}</div>
|
4763 | ` : ''}
|
4764 | ${needsPagination(this.passedParams) ? `
|
4765 | <div part="pagination" class="swiper-pagination"></div>
|
4766 | ` : ''}
|
4767 | ${needsScrollbar(this.passedParams) ? `
|
4768 | <div part="scrollbar" class="swiper-scrollbar"></div>
|
4769 | ` : ''}
|
4770 | `;
|
4771 | this.shadowRoot.appendChild(el);
|
4772 | this.rendered = true;
|
4773 | }
|
4774 | initialize() {
|
4775 | var _this = this;
|
4776 | if (this.initialized) return;
|
4777 | this.initialized = true;
|
4778 | const {
|
4779 | params: swiperParams,
|
4780 | passedParams
|
4781 | } = getParams(this);
|
4782 | this.swiperParams = swiperParams;
|
4783 | this.passedParams = passedParams;
|
4784 | delete this.swiperParams.init;
|
4785 | this.render();
|
4786 |
|
4787 |
|
4788 | this.swiper = new Swiper(this.shadowRoot.querySelector('.swiper'), {
|
4789 | ...(swiperParams.virtual ? {} : {
|
4790 | observer: true,
|
4791 | observeSlideChildren: this.slideSlots > 0
|
4792 | }),
|
4793 | ...swiperParams,
|
4794 | touchEventsTarget: 'container',
|
4795 | onAny: function (name) {
|
4796 | if (name === 'observerUpdate') {
|
4797 | _this.calcSlideSlots();
|
4798 | }
|
4799 | const eventName = swiperParams.eventsPrefix ? `${swiperParams.eventsPrefix}${name.toLowerCase()}` : name.toLowerCase();
|
4800 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
4801 | args[_key - 1] = arguments[_key];
|
4802 | }
|
4803 | const event = new CustomEvent(eventName, {
|
4804 | detail: args,
|
4805 | bubbles: name !== 'hashChange',
|
4806 | cancelable: true
|
4807 | });
|
4808 | _this.dispatchEvent(event);
|
4809 | }
|
4810 | });
|
4811 | }
|
4812 | connectedCallback() {
|
4813 | if (this.initialized && this.nested && this.closest('swiper-slide') && this.closest('swiper-slide').swiperLoopMoveDOM) {
|
4814 | return;
|
4815 | }
|
4816 | if (this.init === false || this.getAttribute('init') === 'false') {
|
4817 | return;
|
4818 | }
|
4819 | this.initialize();
|
4820 | }
|
4821 | disconnectedCallback() {
|
4822 | if (this.nested && this.closest('swiper-slide') && this.closest('swiper-slide').swiperLoopMoveDOM) {
|
4823 | return;
|
4824 | }
|
4825 | if (this.swiper && this.swiper.destroy) {
|
4826 | this.swiper.destroy();
|
4827 | }
|
4828 | this.initialized = false;
|
4829 | }
|
4830 | updateSwiperOnPropChange(propName, propValue) {
|
4831 | const {
|
4832 | params: swiperParams,
|
4833 | passedParams
|
4834 | } = getParams(this, propName, propValue);
|
4835 | this.passedParams = passedParams;
|
4836 | this.swiperParams = swiperParams;
|
4837 | if (this.swiper && this.swiper.params[propName] === propValue) {
|
4838 | return;
|
4839 | }
|
4840 | updateSwiper({
|
4841 | swiper: this.swiper,
|
4842 | passedParams: this.passedParams,
|
4843 | changedParams: [attrToProp(propName)],
|
4844 | ...(propName === 'navigation' && passedParams[propName] ? {
|
4845 | prevEl: '.swiper-button-prev',
|
4846 | nextEl: '.swiper-button-next'
|
4847 | } : {}),
|
4848 | ...(propName === 'pagination' && passedParams[propName] ? {
|
4849 | paginationEl: '.swiper-pagination'
|
4850 | } : {}),
|
4851 | ...(propName === 'scrollbar' && passedParams[propName] ? {
|
4852 | scrollbarEl: '.swiper-scrollbar'
|
4853 | } : {})
|
4854 | });
|
4855 | }
|
4856 | attributeChangedCallback(attr, prevValue, newValue) {
|
4857 | if (!this.initialized) return;
|
4858 | if (prevValue === 'true' && newValue === null) {
|
4859 | newValue = false;
|
4860 | }
|
4861 | this.updateSwiperOnPropChange(attr, newValue);
|
4862 | }
|
4863 | static get observedAttributes() {
|
4864 | const attrs = paramsList.filter(param => param.includes('_')).map(param => param.replace(/[A-Z]/g, v => `-${v}`).replace('_', '').toLowerCase());
|
4865 | return attrs;
|
4866 | }
|
4867 | }
|
4868 | paramsList.forEach(paramName => {
|
4869 | if (paramName === 'init') return;
|
4870 | paramName = paramName.replace('_', '');
|
4871 | Object.defineProperty(SwiperContainer.prototype, paramName, {
|
4872 | configurable: true,
|
4873 | get() {
|
4874 | return (this.passedParams || {})[paramName];
|
4875 | },
|
4876 | set(value) {
|
4877 | if (!this.passedParams) this.passedParams = {};
|
4878 | this.passedParams[paramName] = value;
|
4879 | if (!this.initialized) return;
|
4880 | this.updateSwiperOnPropChange(paramName, value);
|
4881 | }
|
4882 | });
|
4883 | });
|
4884 | class SwiperSlide extends ClassToExtend {
|
4885 | constructor() {
|
4886 | super();
|
4887 | this.attachShadow({
|
4888 | mode: 'open'
|
4889 | });
|
4890 | }
|
4891 | render() {
|
4892 | const lazy = this.lazy || this.getAttribute('lazy') === '' || this.getAttribute('lazy') === 'true';
|
4893 | addStyle(this.shadowRoot, SwiperSlideCSS);
|
4894 | this.shadowRoot.appendChild(document.createElement('slot'));
|
4895 | if (lazy) {
|
4896 | const lazyDiv = document.createElement('div');
|
4897 | lazyDiv.classList.add('swiper-lazy-preloader');
|
4898 | lazyDiv.part.add('preloader');
|
4899 | this.shadowRoot.appendChild(lazyDiv);
|
4900 | }
|
4901 | }
|
4902 | initialize() {
|
4903 | this.render();
|
4904 | }
|
4905 | connectedCallback() {
|
4906 | this.initialize();
|
4907 | }
|
4908 | }
|
4909 |
|
4910 |
|
4911 | const register = () => {
|
4912 | if (typeof window === 'undefined') return;
|
4913 | if (!window.customElements.get('swiper-container')) window.customElements.define('swiper-container', SwiperContainer);
|
4914 | if (!window.customElements.get('swiper-slide')) window.customElements.define('swiper-slide', SwiperSlide);
|
4915 | };
|
4916 | if (typeof window !== 'undefined') {
|
4917 | window.SwiperElementRegisterParams = params => {
|
4918 | paramsList.push(...params);
|
4919 | };
|
4920 | }
|
4921 |
|
4922 | register();
|
4923 |
|
4924 | })();
|