@salla.sa/twilight-components 2.9.49 → 2.10.1

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