itmar-block-packages 3.0.4 → 3.1.0

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 (163) hide show
  1. package/README.md +138 -0
  2. package/build/cjs/AnimationBlock.js +38 -47
  3. package/build/cjs/AnimationBlock.js.map +1 -1
  4. package/build/cjs/BlockEditWrapper.js +2 -2
  5. package/build/cjs/BlockEditWrapper.js.map +1 -1
  6. package/build/cjs/BlockPlace.js +111 -190
  7. package/build/cjs/BlockPlace.js.map +1 -1
  8. package/build/cjs/DateElm.js +41 -48
  9. package/build/cjs/DateElm.js.map +1 -1
  10. package/build/cjs/DraggableBox.js +3 -8
  11. package/build/cjs/DraggableBox.js.map +1 -1
  12. package/build/cjs/GridControls.js +52 -67
  13. package/build/cjs/GridControls.js.map +1 -1
  14. package/build/cjs/IconSelectControl.js +33 -47
  15. package/build/cjs/IconSelectControl.js.map +1 -1
  16. package/build/cjs/MasonryControl.js.map +1 -1
  17. package/build/cjs/PseudoElm.js +2 -2
  18. package/build/cjs/PseudoElm.js.map +1 -1
  19. package/build/cjs/ShadowStyle.js +35 -63
  20. package/build/cjs/ShadowStyle.js.map +1 -1
  21. package/build/cjs/SwiperControl.js +2 -2
  22. package/build/cjs/SwiperControl.js.map +1 -1
  23. package/build/cjs/ToggleElement.js +3 -3
  24. package/build/cjs/ToggleElement.js.map +1 -1
  25. package/build/cjs/TypographyControls.js +27 -35
  26. package/build/cjs/TypographyControls.js.map +1 -1
  27. package/build/cjs/UpdateAllPostsBlockAttributes.js +14 -20
  28. package/build/cjs/UpdateAllPostsBlockAttributes.js.map +1 -1
  29. package/build/cjs/blockStore.js.map +1 -1
  30. package/build/cjs/customHooks.js +20 -3
  31. package/build/cjs/customHooks.js.map +1 -1
  32. package/build/cjs/formatCreate.js +16 -22
  33. package/build/cjs/formatCreate.js.map +1 -1
  34. package/build/cjs/index.js +3 -0
  35. package/build/cjs/index.js.map +1 -1
  36. package/build/cjs/mediaUpload.js +10 -20
  37. package/build/cjs/mediaUpload.js.map +1 -1
  38. package/build/cjs/styleComponentApply.js +42 -0
  39. package/build/cjs/styleComponentApply.js.map +1 -0
  40. package/build/cjs/types/AnimationBlock.d.ts +1 -1
  41. package/build/cjs/types/BlockEditWrapper.d.ts +1 -1
  42. package/build/cjs/types/BlockPlace.d.ts +3 -3
  43. package/build/cjs/types/DateElm.d.ts +1 -1
  44. package/build/cjs/types/DraggableBox.d.ts +1 -1
  45. package/build/cjs/types/GridControls.d.ts +1 -1
  46. package/build/cjs/types/IconSelectControl.d.ts +1 -1
  47. package/build/cjs/types/PseudoElm.d.ts +1 -1
  48. package/build/cjs/types/ShadowStyle.d.ts +1 -1
  49. package/build/cjs/types/ToggleElement.d.ts +1 -1
  50. package/build/cjs/types/TypographyControls.d.ts +1 -1
  51. package/build/cjs/types/UpdateAllPostsBlockAttributes.d.ts +1 -1
  52. package/build/cjs/types/blockStore.d.ts +8 -6
  53. package/build/cjs/types/customHooks.d.ts +14 -7
  54. package/build/cjs/types/formatCreate.d.ts +1 -1
  55. package/build/cjs/types/index.d.ts +3 -2
  56. package/build/cjs/types/mediaUpload.d.ts +2 -2
  57. package/build/cjs/types/styleComponentApply.d.ts +4 -0
  58. package/build/cjs/types/wordpressApi.d.ts +6 -6
  59. package/build/cjs/wordpressApi.js +112 -139
  60. package/build/cjs/wordpressApi.js.map +1 -1
  61. package/build/esm/AnimationBlock.js +38 -47
  62. package/build/esm/AnimationBlock.js.map +1 -1
  63. package/build/esm/BlockEditWrapper.js +3 -3
  64. package/build/esm/BlockEditWrapper.js.map +1 -1
  65. package/build/esm/BlockPlace.js +111 -190
  66. package/build/esm/BlockPlace.js.map +1 -1
  67. package/build/esm/DateElm.js +39 -46
  68. package/build/esm/DateElm.js.map +1 -1
  69. package/build/esm/DraggableBox.js +3 -8
  70. package/build/esm/DraggableBox.js.map +1 -1
  71. package/build/esm/GridControls.js +52 -67
  72. package/build/esm/GridControls.js.map +1 -1
  73. package/build/esm/IconSelectControl.js +34 -48
  74. package/build/esm/IconSelectControl.js.map +1 -1
  75. package/build/esm/MasonryControl.js.map +1 -1
  76. package/build/esm/PseudoElm.js +2 -2
  77. package/build/esm/PseudoElm.js.map +1 -1
  78. package/build/esm/ShadowStyle.js +35 -63
  79. package/build/esm/ShadowStyle.js.map +1 -1
  80. package/build/esm/SwiperControl.js +1 -1
  81. package/build/esm/ToggleElement.js +3 -3
  82. package/build/esm/ToggleElement.js.map +1 -1
  83. package/build/esm/TypographyControls.js +27 -35
  84. package/build/esm/TypographyControls.js.map +1 -1
  85. package/build/esm/UpdateAllPostsBlockAttributes.js +15 -21
  86. package/build/esm/UpdateAllPostsBlockAttributes.js.map +1 -1
  87. package/build/esm/blockStore.js.map +1 -1
  88. package/build/esm/customHooks.js +21 -5
  89. package/build/esm/customHooks.js.map +1 -1
  90. package/build/esm/formatCreate.js +16 -22
  91. package/build/esm/formatCreate.js.map +1 -1
  92. package/build/esm/index.js +2 -1
  93. package/build/esm/index.js.map +1 -1
  94. package/build/esm/mediaUpload.js +10 -20
  95. package/build/esm/mediaUpload.js.map +1 -1
  96. package/build/esm/styleComponentApply.js +40 -0
  97. package/build/esm/styleComponentApply.js.map +1 -0
  98. package/build/esm/types/AnimationBlock.d.ts +1 -1
  99. package/build/esm/types/BlockEditWrapper.d.ts +1 -1
  100. package/build/esm/types/BlockPlace.d.ts +3 -3
  101. package/build/esm/types/DateElm.d.ts +1 -1
  102. package/build/esm/types/DraggableBox.d.ts +1 -1
  103. package/build/esm/types/GridControls.d.ts +1 -1
  104. package/build/esm/types/IconSelectControl.d.ts +1 -1
  105. package/build/esm/types/PseudoElm.d.ts +1 -1
  106. package/build/esm/types/ShadowStyle.d.ts +1 -1
  107. package/build/esm/types/ToggleElement.d.ts +1 -1
  108. package/build/esm/types/TypographyControls.d.ts +1 -1
  109. package/build/esm/types/UpdateAllPostsBlockAttributes.d.ts +1 -1
  110. package/build/esm/types/blockStore.d.ts +8 -6
  111. package/build/esm/types/customHooks.d.ts +14 -7
  112. package/build/esm/types/formatCreate.d.ts +1 -1
  113. package/build/esm/types/index.d.ts +3 -2
  114. package/build/esm/types/mediaUpload.d.ts +2 -2
  115. package/build/esm/types/styleComponentApply.d.ts +4 -0
  116. package/build/esm/types/wordpressApi.d.ts +6 -6
  117. package/build/esm/wordpressApi.js +113 -140
  118. package/build/esm/wordpressApi.js.map +1 -1
  119. package/package.json +12 -5
  120. package/build/cjs/node_modules/nanoid/non-secure/index.js +0 -15
  121. package/build/cjs/node_modules/nanoid/non-secure/index.js.map +0 -1
  122. package/build/cjs/node_modules/swiper/shared/ssr-window.esm.js +0 -144
  123. package/build/cjs/node_modules/swiper/shared/ssr-window.esm.js.map +0 -1
  124. package/build/cjs/node_modules/swiper/shared/swiper-core.js +0 -3925
  125. package/build/cjs/node_modules/swiper/shared/swiper-core.js.map +0 -1
  126. package/build/cjs/node_modules/swiper/shared/utils.js +0 -294
  127. package/build/cjs/node_modules/swiper/shared/utils.js.map +0 -1
  128. package/build/esm/AnimationBlock.d.ts +0 -22
  129. package/build/esm/BlockEditWrapper.d.ts +0 -7
  130. package/build/esm/BlockPlace.d.ts +0 -49
  131. package/build/esm/BrockInserter.d.ts +0 -6
  132. package/build/esm/DateElm.d.ts +0 -69
  133. package/build/esm/DraggableBox.d.ts +0 -19
  134. package/build/esm/GridControls.d.ts +0 -27
  135. package/build/esm/IconSelectControl.d.ts +0 -17
  136. package/build/esm/JapaneseHolidays.d.ts +0 -6
  137. package/build/esm/MasonryControl.d.ts +0 -35
  138. package/build/esm/PseudoElm.d.ts +0 -11
  139. package/build/esm/ShadowStyle.d.ts +0 -33
  140. package/build/esm/SwiperControl.d.ts +0 -12
  141. package/build/esm/ToggleElement.d.ts +0 -13
  142. package/build/esm/TypographyControls.d.ts +0 -17
  143. package/build/esm/UpdateAllPostsBlockAttributes.d.ts +0 -10
  144. package/build/esm/ZipAddress.d.ts +0 -18
  145. package/build/esm/blockStore.d.ts +0 -15
  146. package/build/esm/cssPropertes.d.ts +0 -53
  147. package/build/esm/customHooks.d.ts +0 -11
  148. package/build/esm/formatCreate.d.ts +0 -18
  149. package/build/esm/hslToRgb.d.ts +0 -23
  150. package/build/esm/index.d.ts +0 -27
  151. package/build/esm/mediaUpload.d.ts +0 -29
  152. package/build/esm/node_modules/nanoid/non-secure/index.js +0 -13
  153. package/build/esm/node_modules/nanoid/non-secure/index.js.map +0 -1
  154. package/build/esm/node_modules/swiper/shared/ssr-window.esm.js +0 -141
  155. package/build/esm/node_modules/swiper/shared/ssr-window.esm.js.map +0 -1
  156. package/build/esm/node_modules/swiper/shared/swiper-core.js +0 -3922
  157. package/build/esm/node_modules/swiper/shared/swiper-core.js.map +0 -1
  158. package/build/esm/node_modules/swiper/shared/utils.js +0 -274
  159. package/build/esm/node_modules/swiper/shared/utils.js.map +0 -1
  160. package/build/esm/pickupStore.d.ts +0 -39
  161. package/build/esm/shopfiApi.d.ts +0 -18
  162. package/build/esm/validationCheck.d.ts +0 -5
  163. package/build/esm/wordpressApi.d.ts +0 -99
@@ -1,3925 +0,0 @@
1
- 'use strict';
2
-
3
- var ssrWindow_esm = require('./ssr-window.esm.js');
4
- var utils = require('./utils.js');
5
-
6
- let support;
7
- function calcSupport() {
8
- const window = ssrWindow_esm.a();
9
- const document = ssrWindow_esm.g();
10
- return {
11
- smoothScroll: document.documentElement && document.documentElement.style && 'scrollBehavior' in document.documentElement.style,
12
- touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch)
13
- };
14
- }
15
- function getSupport() {
16
- if (!support) {
17
- support = calcSupport();
18
- }
19
- return support;
20
- }
21
-
22
- let deviceCached;
23
- function calcDevice({
24
- userAgent
25
- } = {}) {
26
- const support = getSupport();
27
- const window = ssrWindow_esm.a();
28
- const platform = window.navigator.platform;
29
- const ua = userAgent || window.navigator.userAgent;
30
- const device = {
31
- ios: false,
32
- android: false
33
- };
34
- const screenWidth = window.screen.width;
35
- const screenHeight = window.screen.height;
36
- const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line
37
- let ipad = ua.match(/(iPad)(?!\1).*OS\s([\d_]+)/);
38
- const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
39
- const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
40
- const windows = platform === 'Win32';
41
- let macos = platform === 'MacIntel';
42
-
43
- // iPadOs 13 fix
44
- const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
45
- if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) {
46
- ipad = ua.match(/(Version)\/([\d.]+)/);
47
- if (!ipad) ipad = [0, 1, '13_0_0'];
48
- macos = false;
49
- }
50
-
51
- // Android
52
- if (android && !windows) {
53
- device.os = 'android';
54
- device.android = true;
55
- }
56
- if (ipad || iphone || ipod) {
57
- device.os = 'ios';
58
- device.ios = true;
59
- }
60
-
61
- // Export object
62
- return device;
63
- }
64
- function getDevice(overrides = {}) {
65
- if (!deviceCached) {
66
- deviceCached = calcDevice(overrides);
67
- }
68
- return deviceCached;
69
- }
70
-
71
- let browser;
72
- function calcBrowser() {
73
- const window = ssrWindow_esm.a();
74
- const device = getDevice();
75
- let needPerspectiveFix = false;
76
- function isSafari() {
77
- const ua = window.navigator.userAgent.toLowerCase();
78
- return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0;
79
- }
80
- if (isSafari()) {
81
- const ua = String(window.navigator.userAgent);
82
- if (ua.includes('Version/')) {
83
- const [major, minor] = ua.split('Version/')[1].split(' ')[0].split('.').map(num => Number(num));
84
- needPerspectiveFix = major < 16 || major === 16 && minor < 2;
85
- }
86
- }
87
- const isWebView = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent);
88
- const isSafariBrowser = isSafari();
89
- const need3dFix = isSafariBrowser || isWebView && device.ios;
90
- return {
91
- isSafari: needPerspectiveFix || isSafariBrowser,
92
- needPerspectiveFix,
93
- need3dFix,
94
- isWebView
95
- };
96
- }
97
- function getBrowser() {
98
- if (!browser) {
99
- browser = calcBrowser();
100
- }
101
- return browser;
102
- }
103
-
104
- function Resize({
105
- swiper,
106
- on,
107
- emit
108
- }) {
109
- const window = ssrWindow_esm.a();
110
- let observer = null;
111
- let animationFrame = null;
112
- const resizeHandler = () => {
113
- if (!swiper || swiper.destroyed || !swiper.initialized) return;
114
- emit('beforeResize');
115
- emit('resize');
116
- };
117
- const createObserver = () => {
118
- if (!swiper || swiper.destroyed || !swiper.initialized) return;
119
- observer = new ResizeObserver(entries => {
120
- animationFrame = window.requestAnimationFrame(() => {
121
- const {
122
- width,
123
- height
124
- } = swiper;
125
- let newWidth = width;
126
- let newHeight = height;
127
- entries.forEach(({
128
- contentBoxSize,
129
- contentRect,
130
- target
131
- }) => {
132
- if (target && target !== swiper.el) return;
133
- newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
134
- newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
135
- });
136
- if (newWidth !== width || newHeight !== height) {
137
- resizeHandler();
138
- }
139
- });
140
- });
141
- observer.observe(swiper.el);
142
- };
143
- const removeObserver = () => {
144
- if (animationFrame) {
145
- window.cancelAnimationFrame(animationFrame);
146
- }
147
- if (observer && observer.unobserve && swiper.el) {
148
- observer.unobserve(swiper.el);
149
- observer = null;
150
- }
151
- };
152
- const orientationChangeHandler = () => {
153
- if (!swiper || swiper.destroyed || !swiper.initialized) return;
154
- emit('orientationchange');
155
- };
156
- on('init', () => {
157
- if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
158
- createObserver();
159
- return;
160
- }
161
- window.addEventListener('resize', resizeHandler);
162
- window.addEventListener('orientationchange', orientationChangeHandler);
163
- });
164
- on('destroy', () => {
165
- removeObserver();
166
- window.removeEventListener('resize', resizeHandler);
167
- window.removeEventListener('orientationchange', orientationChangeHandler);
168
- });
169
- }
170
-
171
- function Observer({
172
- swiper,
173
- extendParams,
174
- on,
175
- emit
176
- }) {
177
- const observers = [];
178
- const window = ssrWindow_esm.a();
179
- const attach = (target, options = {}) => {
180
- const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
181
- const observer = new ObserverFunc(mutations => {
182
- // The observerUpdate event should only be triggered
183
- // once despite the number of mutations. Additional
184
- // triggers are redundant and are very costly
185
- if (swiper.__preventObserver__) return;
186
- if (mutations.length === 1) {
187
- emit('observerUpdate', mutations[0]);
188
- return;
189
- }
190
- const observerUpdate = function observerUpdate() {
191
- emit('observerUpdate', mutations[0]);
192
- };
193
- if (window.requestAnimationFrame) {
194
- window.requestAnimationFrame(observerUpdate);
195
- } else {
196
- window.setTimeout(observerUpdate, 0);
197
- }
198
- });
199
- observer.observe(target, {
200
- attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
201
- childList: swiper.isElement || (typeof options.childList === 'undefined' ? true : options).childList,
202
- characterData: typeof options.characterData === 'undefined' ? true : options.characterData
203
- });
204
- observers.push(observer);
205
- };
206
- const init = () => {
207
- if (!swiper.params.observer) return;
208
- if (swiper.params.observeParents) {
209
- const containerParents = utils.d(swiper.hostEl);
210
- for (let i = 0; i < containerParents.length; i += 1) {
211
- attach(containerParents[i]);
212
- }
213
- }
214
- // Observe container
215
- attach(swiper.hostEl, {
216
- childList: swiper.params.observeSlideChildren
217
- });
218
-
219
- // Observe wrapper
220
- attach(swiper.wrapperEl, {
221
- attributes: false
222
- });
223
- };
224
- const destroy = () => {
225
- observers.forEach(observer => {
226
- observer.disconnect();
227
- });
228
- observers.splice(0, observers.length);
229
- };
230
- extendParams({
231
- observer: false,
232
- observeParents: false,
233
- observeSlideChildren: false
234
- });
235
- on('init', init);
236
- on('destroy', destroy);
237
- }
238
-
239
- /* eslint-disable no-underscore-dangle */
240
-
241
- var eventsEmitter = {
242
- on(events, handler, priority) {
243
- const self = this;
244
- if (!self.eventsListeners || self.destroyed) return self;
245
- if (typeof handler !== 'function') return self;
246
- const method = priority ? 'unshift' : 'push';
247
- events.split(' ').forEach(event => {
248
- if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
249
- self.eventsListeners[event][method](handler);
250
- });
251
- return self;
252
- },
253
- once(events, handler, priority) {
254
- const self = this;
255
- if (!self.eventsListeners || self.destroyed) return self;
256
- if (typeof handler !== 'function') return self;
257
- function onceHandler(...args) {
258
- self.off(events, onceHandler);
259
- if (onceHandler.__emitterProxy) {
260
- delete onceHandler.__emitterProxy;
261
- }
262
- handler.apply(self, args);
263
- }
264
- onceHandler.__emitterProxy = handler;
265
- return self.on(events, onceHandler, priority);
266
- },
267
- onAny(handler, priority) {
268
- const self = this;
269
- if (!self.eventsListeners || self.destroyed) return self;
270
- if (typeof handler !== 'function') return self;
271
- const method = priority ? 'unshift' : 'push';
272
- if (self.eventsAnyListeners.indexOf(handler) < 0) {
273
- self.eventsAnyListeners[method](handler);
274
- }
275
- return self;
276
- },
277
- offAny(handler) {
278
- const self = this;
279
- if (!self.eventsListeners || self.destroyed) return self;
280
- if (!self.eventsAnyListeners) return self;
281
- const index = self.eventsAnyListeners.indexOf(handler);
282
- if (index >= 0) {
283
- self.eventsAnyListeners.splice(index, 1);
284
- }
285
- return self;
286
- },
287
- off(events, handler) {
288
- const self = this;
289
- if (!self.eventsListeners || self.destroyed) return self;
290
- if (!self.eventsListeners) return self;
291
- events.split(' ').forEach(event => {
292
- if (typeof handler === 'undefined') {
293
- self.eventsListeners[event] = [];
294
- } else if (self.eventsListeners[event]) {
295
- self.eventsListeners[event].forEach((eventHandler, index) => {
296
- if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) {
297
- self.eventsListeners[event].splice(index, 1);
298
- }
299
- });
300
- }
301
- });
302
- return self;
303
- },
304
- emit(...args) {
305
- const self = this;
306
- if (!self.eventsListeners || self.destroyed) return self;
307
- if (!self.eventsListeners) return self;
308
- let events;
309
- let data;
310
- let context;
311
- if (typeof args[0] === 'string' || Array.isArray(args[0])) {
312
- events = args[0];
313
- data = args.slice(1, args.length);
314
- context = self;
315
- } else {
316
- events = args[0].events;
317
- data = args[0].data;
318
- context = args[0].context || self;
319
- }
320
- data.unshift(context);
321
- const eventsArray = Array.isArray(events) ? events : events.split(' ');
322
- eventsArray.forEach(event => {
323
- if (self.eventsAnyListeners && self.eventsAnyListeners.length) {
324
- self.eventsAnyListeners.forEach(eventHandler => {
325
- eventHandler.apply(context, [event, ...data]);
326
- });
327
- }
328
- if (self.eventsListeners && self.eventsListeners[event]) {
329
- self.eventsListeners[event].forEach(eventHandler => {
330
- eventHandler.apply(context, data);
331
- });
332
- }
333
- });
334
- return self;
335
- }
336
- };
337
-
338
- function updateSize() {
339
- const swiper = this;
340
- let width;
341
- let height;
342
- const el = swiper.el;
343
- if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
344
- width = swiper.params.width;
345
- } else {
346
- width = el.clientWidth;
347
- }
348
- if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
349
- height = swiper.params.height;
350
- } else {
351
- height = el.clientHeight;
352
- }
353
- if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
354
- return;
355
- }
356
-
357
- // Subtract paddings
358
- width = width - parseInt(utils.q(el, 'padding-left') || 0, 10) - parseInt(utils.q(el, 'padding-right') || 0, 10);
359
- height = height - parseInt(utils.q(el, 'padding-top') || 0, 10) - parseInt(utils.q(el, 'padding-bottom') || 0, 10);
360
- if (Number.isNaN(width)) width = 0;
361
- if (Number.isNaN(height)) height = 0;
362
- Object.assign(swiper, {
363
- width,
364
- height,
365
- size: swiper.isHorizontal() ? width : height
366
- });
367
- }
368
-
369
- function updateSlides() {
370
- const swiper = this;
371
- function getDirectionPropertyValue(node, label) {
372
- return parseFloat(node.getPropertyValue(swiper.getDirectionLabel(label)) || 0);
373
- }
374
- const params = swiper.params;
375
- const {
376
- wrapperEl,
377
- slidesEl,
378
- rtlTranslate: rtl,
379
- wrongRTL
380
- } = swiper;
381
- const isVirtual = swiper.virtual && params.virtual.enabled;
382
- const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
383
- const slides = utils.e(slidesEl, `.${swiper.params.slideClass}, swiper-slide`);
384
- const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
385
- let snapGrid = [];
386
- const slidesGrid = [];
387
- const slidesSizesGrid = [];
388
- let offsetBefore = params.slidesOffsetBefore;
389
- if (typeof offsetBefore === 'function') {
390
- offsetBefore = params.slidesOffsetBefore.call(swiper);
391
- }
392
- let offsetAfter = params.slidesOffsetAfter;
393
- if (typeof offsetAfter === 'function') {
394
- offsetAfter = params.slidesOffsetAfter.call(swiper);
395
- }
396
- const previousSnapGridLength = swiper.snapGrid.length;
397
- const previousSlidesGridLength = swiper.slidesGrid.length;
398
- const swiperSize = swiper.size - offsetBefore - offsetAfter;
399
- let spaceBetween = params.spaceBetween;
400
- let slidePosition = -offsetBefore;
401
- let prevSlideSize = 0;
402
- let index = 0;
403
- if (typeof swiperSize === 'undefined') {
404
- return;
405
- }
406
- if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
407
- spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize;
408
- } else if (typeof spaceBetween === 'string') {
409
- spaceBetween = parseFloat(spaceBetween);
410
- }
411
- swiper.virtualSize = -spaceBetween - offsetBefore - offsetAfter;
412
-
413
- // reset margins
414
- slides.forEach(slideEl => {
415
- if (rtl) {
416
- slideEl.style.marginLeft = '';
417
- } else {
418
- slideEl.style.marginRight = '';
419
- }
420
- slideEl.style.marginBottom = '';
421
- slideEl.style.marginTop = '';
422
- });
423
-
424
- // reset cssMode offsets
425
- if (params.centeredSlides && params.cssMode) {
426
- utils.b(wrapperEl, '--swiper-centered-offset-before', '');
427
- utils.b(wrapperEl, '--swiper-centered-offset-after', '');
428
- }
429
-
430
- // set cssMode offsets
431
- if (params.cssMode) {
432
- utils.b(wrapperEl, '--swiper-slides-offset-before', `${offsetBefore}px`);
433
- utils.b(wrapperEl, '--swiper-slides-offset-after', `${offsetAfter}px`);
434
- }
435
- const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid;
436
- if (gridEnabled) {
437
- swiper.grid.initSlides(slides);
438
- } else if (swiper.grid) {
439
- swiper.grid.unsetSlides();
440
- }
441
-
442
- // Calc slides
443
- let slideSize;
444
- const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => {
445
- return typeof params.breakpoints[key].slidesPerView !== 'undefined';
446
- }).length > 0;
447
- for (let i = 0; i < slidesLength; i += 1) {
448
- slideSize = 0;
449
- const slide = slides[i];
450
- if (slide) {
451
- if (gridEnabled) {
452
- swiper.grid.updateSlide(i, slide, slides);
453
- }
454
- if (utils.q(slide, 'display') === 'none') continue; // eslint-disable-line
455
- }
456
-
457
- if (isVirtual && params.slidesPerView === 'auto') {
458
- if (params.virtual.slidesPerViewAutoSlideSize) {
459
- slideSize = params.virtual.slidesPerViewAutoSlideSize;
460
- }
461
- if (slideSize && slide) {
462
- if (params.roundLengths) slideSize = Math.floor(slideSize);
463
- slide.style[swiper.getDirectionLabel('width')] = `${slideSize}px`;
464
- }
465
- } else if (params.slidesPerView === 'auto') {
466
- if (shouldResetSlideSize) {
467
- slide.style[swiper.getDirectionLabel('width')] = ``;
468
- }
469
- const slideStyles = getComputedStyle(slide);
470
- const currentTransform = slide.style.transform;
471
- const currentWebKitTransform = slide.style.webkitTransform;
472
- if (currentTransform) {
473
- slide.style.transform = 'none';
474
- }
475
- if (currentWebKitTransform) {
476
- slide.style.webkitTransform = 'none';
477
- }
478
- if (params.roundLengths) {
479
- slideSize = swiper.isHorizontal() ? utils.i(slide, 'width') : utils.i(slide, 'height');
480
- } else {
481
- // eslint-disable-next-line
482
- const width = getDirectionPropertyValue(slideStyles, 'width');
483
- const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left');
484
- const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right');
485
- const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left');
486
- const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right');
487
- const boxSizing = slideStyles.getPropertyValue('box-sizing');
488
- if (boxSizing && boxSizing === 'border-box') {
489
- slideSize = width + marginLeft + marginRight;
490
- } else {
491
- const {
492
- clientWidth,
493
- offsetWidth
494
- } = slide;
495
- slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
496
- }
497
- }
498
- if (currentTransform) {
499
- slide.style.transform = currentTransform;
500
- }
501
- if (currentWebKitTransform) {
502
- slide.style.webkitTransform = currentWebKitTransform;
503
- }
504
- if (params.roundLengths) slideSize = Math.floor(slideSize);
505
- } else {
506
- slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
507
- if (params.roundLengths) slideSize = Math.floor(slideSize);
508
- if (slide) {
509
- slide.style[swiper.getDirectionLabel('width')] = `${slideSize}px`;
510
- }
511
- }
512
- if (slide) {
513
- slide.swiperSlideSize = slideSize;
514
- }
515
- slidesSizesGrid.push(slideSize);
516
- if (params.centeredSlides) {
517
- slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
518
- if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
519
- if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
520
- if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
521
- if (params.roundLengths) slidePosition = Math.floor(slidePosition);
522
- if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
523
- slidesGrid.push(slidePosition);
524
- } else {
525
- if (params.roundLengths) slidePosition = Math.floor(slidePosition);
526
- if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
527
- slidesGrid.push(slidePosition);
528
- slidePosition = slidePosition + slideSize + spaceBetween;
529
- }
530
- swiper.virtualSize += slideSize + spaceBetween;
531
- prevSlideSize = slideSize;
532
- index += 1;
533
- }
534
- swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
535
- if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
536
- wrapperEl.style.width = `${swiper.virtualSize + spaceBetween}px`;
537
- }
538
- if (params.setWrapperSize) {
539
- wrapperEl.style[swiper.getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
540
- }
541
- if (gridEnabled) {
542
- swiper.grid.updateWrapperSize(slideSize, snapGrid);
543
- }
544
-
545
- // Remove last grid elements depending on width
546
- if (!params.centeredSlides) {
547
- // Check if snapToSlideEdge should be applied
548
- const isFractionalSlidesPerView = params.slidesPerView !== 'auto' && params.slidesPerView % 1 !== 0;
549
- const shouldSnapToSlideEdge = params.snapToSlideEdge && !params.loop && (params.slidesPerView === 'auto' || isFractionalSlidesPerView);
550
-
551
- // Calculate the last allowed snap index when snapToSlideEdge is enabled
552
- // This ensures minimum slides are visible at the end
553
- let lastAllowedSnapIndex = snapGrid.length;
554
- if (shouldSnapToSlideEdge) {
555
- let minVisibleSlides;
556
- if (params.slidesPerView === 'auto') {
557
- // For 'auto' mode, calculate how many slides fit based on actual sizes
558
- minVisibleSlides = 1;
559
- let accumulatedSize = 0;
560
- for (let i = slidesSizesGrid.length - 1; i >= 0; i -= 1) {
561
- accumulatedSize += slidesSizesGrid[i] + (i < slidesSizesGrid.length - 1 ? spaceBetween : 0);
562
- if (accumulatedSize <= swiperSize) {
563
- minVisibleSlides = slidesSizesGrid.length - i;
564
- } else {
565
- break;
566
- }
567
- }
568
- } else {
569
- minVisibleSlides = Math.floor(params.slidesPerView);
570
- }
571
- lastAllowedSnapIndex = Math.max(slidesLength - minVisibleSlides, 0);
572
- }
573
- const newSlidesGrid = [];
574
- for (let i = 0; i < snapGrid.length; i += 1) {
575
- let slidesGridItem = snapGrid[i];
576
- if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
577
- if (shouldSnapToSlideEdge) {
578
- // When snapToSlideEdge is enabled, only keep snaps up to lastAllowedSnapIndex
579
- if (i <= lastAllowedSnapIndex) {
580
- newSlidesGrid.push(slidesGridItem);
581
- }
582
- } else if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
583
- // When snapToSlideEdge is disabled, keep snaps that fit within scrollable area
584
- newSlidesGrid.push(slidesGridItem);
585
- }
586
- }
587
- snapGrid = newSlidesGrid;
588
- if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
589
- // Only add edge-aligned snap if snapToSlideEdge is not enabled
590
- if (!shouldSnapToSlideEdge) {
591
- snapGrid.push(swiper.virtualSize - swiperSize);
592
- }
593
- }
594
- }
595
- if (isVirtual && params.loop) {
596
- const size = slidesSizesGrid[0] + spaceBetween;
597
- if (params.slidesPerGroup > 1) {
598
- const groups = Math.ceil((swiper.virtual.slidesBefore + swiper.virtual.slidesAfter) / params.slidesPerGroup);
599
- const groupSize = size * params.slidesPerGroup;
600
- for (let i = 0; i < groups; i += 1) {
601
- snapGrid.push(snapGrid[snapGrid.length - 1] + groupSize);
602
- }
603
- }
604
- for (let i = 0; i < swiper.virtual.slidesBefore + swiper.virtual.slidesAfter; i += 1) {
605
- if (params.slidesPerGroup === 1) {
606
- snapGrid.push(snapGrid[snapGrid.length - 1] + size);
607
- }
608
- slidesGrid.push(slidesGrid[slidesGrid.length - 1] + size);
609
- swiper.virtualSize += size;
610
- }
611
- }
612
- if (snapGrid.length === 0) snapGrid = [0];
613
- if (spaceBetween !== 0) {
614
- const key = swiper.isHorizontal() && rtl ? 'marginLeft' : swiper.getDirectionLabel('marginRight');
615
- slides.filter((_, slideIndex) => {
616
- if (!params.cssMode || params.loop) return true;
617
- if (slideIndex === slides.length - 1) {
618
- return false;
619
- }
620
- return true;
621
- }).forEach(slideEl => {
622
- slideEl.style[key] = `${spaceBetween}px`;
623
- });
624
- }
625
- if (params.centeredSlides && params.centeredSlidesBounds) {
626
- let allSlidesSize = 0;
627
- slidesSizesGrid.forEach(slideSizeValue => {
628
- allSlidesSize += slideSizeValue + (spaceBetween || 0);
629
- });
630
- allSlidesSize -= spaceBetween;
631
- const maxSnap = allSlidesSize > swiperSize ? allSlidesSize - swiperSize : 0;
632
- snapGrid = snapGrid.map(snap => {
633
- if (snap <= 0) return -offsetBefore;
634
- if (snap > maxSnap) return maxSnap + offsetAfter;
635
- return snap;
636
- });
637
- }
638
- if (params.centerInsufficientSlides) {
639
- let allSlidesSize = 0;
640
- slidesSizesGrid.forEach(slideSizeValue => {
641
- allSlidesSize += slideSizeValue + (spaceBetween || 0);
642
- });
643
- allSlidesSize -= spaceBetween;
644
- if (allSlidesSize < swiperSize) {
645
- const allSlidesOffset = (swiperSize - allSlidesSize) / 2;
646
- snapGrid.forEach((snap, snapIndex) => {
647
- snapGrid[snapIndex] = snap - allSlidesOffset;
648
- });
649
- slidesGrid.forEach((snap, snapIndex) => {
650
- slidesGrid[snapIndex] = snap + allSlidesOffset;
651
- });
652
- }
653
- }
654
- Object.assign(swiper, {
655
- slides,
656
- snapGrid,
657
- slidesGrid,
658
- slidesSizesGrid
659
- });
660
- if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) {
661
- utils.b(wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`);
662
- utils.b(wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`);
663
- const addToSnapGrid = -swiper.snapGrid[0];
664
- const addToSlidesGrid = -swiper.slidesGrid[0];
665
- swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid);
666
- swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid);
667
- }
668
- if (slidesLength !== previousSlidesLength) {
669
- swiper.emit('slidesLengthChange');
670
- }
671
- if (snapGrid.length !== previousSnapGridLength) {
672
- if (swiper.params.watchOverflow) swiper.checkOverflow();
673
- swiper.emit('snapGridLengthChange');
674
- }
675
- if (slidesGrid.length !== previousSlidesGridLength) {
676
- swiper.emit('slidesGridLengthChange');
677
- }
678
- if (params.watchSlidesProgress) {
679
- swiper.updateSlidesOffset();
680
- }
681
- swiper.emit('slidesUpdated');
682
- if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
683
- const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`;
684
- const hasClassBackfaceClassAdded = swiper.el.classList.contains(backFaceHiddenClass);
685
- if (slidesLength <= params.maxBackfaceHiddenSlides) {
686
- if (!hasClassBackfaceClassAdded) swiper.el.classList.add(backFaceHiddenClass);
687
- } else if (hasClassBackfaceClassAdded) {
688
- swiper.el.classList.remove(backFaceHiddenClass);
689
- }
690
- }
691
- }
692
-
693
- function updateAutoHeight(speed) {
694
- const swiper = this;
695
- const activeSlides = [];
696
- const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
697
- let newHeight = 0;
698
- let i;
699
- if (typeof speed === 'number') {
700
- swiper.setTransition(speed);
701
- } else if (speed === true) {
702
- swiper.setTransition(swiper.params.speed);
703
- }
704
- const getSlideByIndex = index => {
705
- if (isVirtual) {
706
- return swiper.slides[swiper.getSlideIndexByData(index)];
707
- }
708
- return swiper.slides[index];
709
- };
710
- // Find slides currently in view
711
- if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
712
- if (swiper.params.centeredSlides) {
713
- (swiper.visibleSlides || []).forEach(slide => {
714
- activeSlides.push(slide);
715
- });
716
- } else {
717
- for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
718
- const index = swiper.activeIndex + i;
719
- if (index > swiper.slides.length && !isVirtual) break;
720
- activeSlides.push(getSlideByIndex(index));
721
- }
722
- }
723
- } else {
724
- activeSlides.push(getSlideByIndex(swiper.activeIndex));
725
- }
726
-
727
- // Find new height from highest slide in view
728
- for (i = 0; i < activeSlides.length; i += 1) {
729
- if (typeof activeSlides[i] !== 'undefined') {
730
- const height = activeSlides[i].offsetHeight;
731
- newHeight = height > newHeight ? height : newHeight;
732
- }
733
- }
734
-
735
- // Update Height
736
- if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
737
- }
738
-
739
- function updateSlidesOffset() {
740
- const swiper = this;
741
- const slides = swiper.slides;
742
- // eslint-disable-next-line
743
- const minusOffset = swiper.isElement ? swiper.isHorizontal() ? swiper.wrapperEl.offsetLeft : swiper.wrapperEl.offsetTop : 0;
744
- for (let i = 0; i < slides.length; i += 1) {
745
- slides[i].swiperSlideOffset = (swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop) - minusOffset - swiper.cssOverflowAdjustment();
746
- }
747
- }
748
-
749
- const toggleSlideClasses$1 = (slideEl, condition, className) => {
750
- if (condition && !slideEl.classList.contains(className)) {
751
- slideEl.classList.add(className);
752
- } else if (!condition && slideEl.classList.contains(className)) {
753
- slideEl.classList.remove(className);
754
- }
755
- };
756
- function updateSlidesProgress(translate = this && this.translate || 0) {
757
- const swiper = this;
758
- const params = swiper.params;
759
- const {
760
- slides,
761
- rtlTranslate: rtl,
762
- snapGrid
763
- } = swiper;
764
- if (slides.length === 0) return;
765
- if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
766
- let offsetCenter = -translate;
767
- if (rtl) offsetCenter = translate;
768
- swiper.visibleSlidesIndexes = [];
769
- swiper.visibleSlides = [];
770
- let spaceBetween = params.spaceBetween;
771
- if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
772
- spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiper.size;
773
- } else if (typeof spaceBetween === 'string') {
774
- spaceBetween = parseFloat(spaceBetween);
775
- }
776
- for (let i = 0; i < slides.length; i += 1) {
777
- const slide = slides[i];
778
- let slideOffset = slide.swiperSlideOffset;
779
- if (params.cssMode && params.centeredSlides) {
780
- slideOffset -= slides[0].swiperSlideOffset;
781
- }
782
- const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
783
- const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
784
- const slideBefore = -(offsetCenter - slideOffset);
785
- const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
786
- const isFullyVisible = slideBefore >= 0 && slideBefore <= swiper.size - swiper.slidesSizesGrid[i];
787
- const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size;
788
- if (isVisible) {
789
- swiper.visibleSlides.push(slide);
790
- swiper.visibleSlidesIndexes.push(i);
791
- }
792
- toggleSlideClasses$1(slide, isVisible, params.slideVisibleClass);
793
- toggleSlideClasses$1(slide, isFullyVisible, params.slideFullyVisibleClass);
794
- slide.progress = rtl ? -slideProgress : slideProgress;
795
- slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress;
796
- }
797
- }
798
-
799
- function updateProgress(translate) {
800
- const swiper = this;
801
- if (typeof translate === 'undefined') {
802
- const multiplier = swiper.rtlTranslate ? -1 : 1;
803
- // eslint-disable-next-line
804
- translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
805
- }
806
- const params = swiper.params;
807
- const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
808
- let {
809
- progress,
810
- isBeginning,
811
- isEnd,
812
- progressLoop
813
- } = swiper;
814
- const wasBeginning = isBeginning;
815
- const wasEnd = isEnd;
816
- if (translatesDiff === 0) {
817
- progress = 0;
818
- isBeginning = true;
819
- isEnd = true;
820
- } else {
821
- progress = (translate - swiper.minTranslate()) / translatesDiff;
822
- const isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1;
823
- const isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1;
824
- isBeginning = isBeginningRounded || progress <= 0;
825
- isEnd = isEndRounded || progress >= 1;
826
- if (isBeginningRounded) progress = 0;
827
- if (isEndRounded) progress = 1;
828
- }
829
- if (params.loop) {
830
- const firstSlideIndex = swiper.getSlideIndexByData(0);
831
- const lastSlideIndex = swiper.getSlideIndexByData(swiper.slides.length - 1);
832
- const firstSlideTranslate = swiper.slidesGrid[firstSlideIndex];
833
- const lastSlideTranslate = swiper.slidesGrid[lastSlideIndex];
834
- const translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1];
835
- const translateAbs = Math.abs(translate);
836
- if (translateAbs >= firstSlideTranslate) {
837
- progressLoop = (translateAbs - firstSlideTranslate) / translateMax;
838
- } else {
839
- progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax;
840
- }
841
- if (progressLoop > 1) progressLoop -= 1;
842
- }
843
- Object.assign(swiper, {
844
- progress,
845
- progressLoop,
846
- isBeginning,
847
- isEnd
848
- });
849
- if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
850
- if (isBeginning && !wasBeginning) {
851
- swiper.emit('reachBeginning toEdge');
852
- }
853
- if (isEnd && !wasEnd) {
854
- swiper.emit('reachEnd toEdge');
855
- }
856
- if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
857
- swiper.emit('fromEdge');
858
- }
859
- swiper.emit('progress', progress);
860
- }
861
-
862
- const toggleSlideClasses = (slideEl, condition, className) => {
863
- if (condition && !slideEl.classList.contains(className)) {
864
- slideEl.classList.add(className);
865
- } else if (!condition && slideEl.classList.contains(className)) {
866
- slideEl.classList.remove(className);
867
- }
868
- };
869
- function updateSlidesClasses() {
870
- const swiper = this;
871
- const {
872
- slides,
873
- params,
874
- slidesEl,
875
- activeIndex
876
- } = swiper;
877
- const isVirtual = swiper.virtual && params.virtual.enabled;
878
- const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
879
- const getFilteredSlide = selector => {
880
- return utils.e(slidesEl, `.${params.slideClass}${selector}, swiper-slide${selector}`)[0];
881
- };
882
- let activeSlide;
883
- let prevSlide;
884
- let nextSlide;
885
- if (isVirtual) {
886
- if (params.loop) {
887
- let slideIndex = activeIndex - swiper.virtual.slidesBefore;
888
- if (slideIndex < 0) slideIndex = swiper.virtual.slides.length + slideIndex;
889
- if (slideIndex >= swiper.virtual.slides.length) slideIndex -= swiper.virtual.slides.length;
890
- activeSlide = getFilteredSlide(`[data-swiper-slide-index="${slideIndex}"]`);
891
- } else {
892
- activeSlide = getFilteredSlide(`[data-swiper-slide-index="${activeIndex}"]`);
893
- }
894
- } else {
895
- if (gridEnabled) {
896
- activeSlide = slides.find(slideEl => slideEl.column === activeIndex);
897
- nextSlide = slides.find(slideEl => slideEl.column === activeIndex + 1);
898
- prevSlide = slides.find(slideEl => slideEl.column === activeIndex - 1);
899
- } else {
900
- activeSlide = slides[activeIndex];
901
- }
902
- }
903
- if (activeSlide) {
904
- if (!gridEnabled) {
905
- // Next Slide
906
- nextSlide = utils.r(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
907
- if (params.loop && !nextSlide) {
908
- nextSlide = slides[0];
909
- }
910
-
911
- // Prev Slide
912
- prevSlide = utils.t(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
913
- if (params.loop && !prevSlide === 0) {
914
- prevSlide = slides[slides.length - 1];
915
- }
916
- }
917
- }
918
- slides.forEach(slideEl => {
919
- toggleSlideClasses(slideEl, slideEl === activeSlide, params.slideActiveClass);
920
- toggleSlideClasses(slideEl, slideEl === nextSlide, params.slideNextClass);
921
- toggleSlideClasses(slideEl, slideEl === prevSlide, params.slidePrevClass);
922
- });
923
- swiper.emitSlidesClasses();
924
- }
925
-
926
- const processLazyPreloader = (swiper, imageEl) => {
927
- if (!swiper || swiper.destroyed || !swiper.params) return;
928
- const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`;
929
- const slideEl = imageEl.closest(slideSelector());
930
- if (slideEl) {
931
- let lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
932
- if (!lazyEl && swiper.isElement) {
933
- if (slideEl.shadowRoot) {
934
- lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
935
- } else {
936
- // init later
937
- requestAnimationFrame(() => {
938
- if (slideEl.shadowRoot) {
939
- lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
940
- if (lazyEl && !lazyEl.lazyPreloaderManaged) lazyEl.remove();
941
- }
942
- });
943
- }
944
- }
945
- // Skip removal if managed by React/Vue component
946
- if (lazyEl && !lazyEl.lazyPreloaderManaged) lazyEl.remove();
947
- }
948
- };
949
- const unlazy = (swiper, index) => {
950
- if (!swiper.slides[index]) return;
951
- const imageEl = swiper.slides[index].querySelector('[loading="lazy"]');
952
- if (imageEl) imageEl.removeAttribute('loading');
953
- };
954
- const preload = swiper => {
955
- if (!swiper || swiper.destroyed || !swiper.params) return;
956
- let amount = swiper.params.lazyPreloadPrevNext;
957
- const len = swiper.slides.length;
958
- if (!len || !amount || amount < 0) return;
959
- amount = Math.min(amount, len);
960
- const slidesPerView = swiper.params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(swiper.params.slidesPerView);
961
- const activeIndex = swiper.activeIndex;
962
- if (swiper.params.grid && swiper.params.grid.rows > 1) {
963
- const activeColumn = activeIndex;
964
- const preloadColumns = [activeColumn - amount];
965
- preloadColumns.push(...Array.from({
966
- length: amount
967
- }).map((_, i) => {
968
- return activeColumn + slidesPerView + i;
969
- }));
970
- swiper.slides.forEach((slideEl, i) => {
971
- if (preloadColumns.includes(slideEl.column)) unlazy(swiper, i);
972
- });
973
- return;
974
- }
975
- const slideIndexLastInView = activeIndex + slidesPerView - 1;
976
- if (swiper.params.rewind || swiper.params.loop) {
977
- for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {
978
- const realIndex = (i % len + len) % len;
979
- if (realIndex < activeIndex || realIndex > slideIndexLastInView) unlazy(swiper, realIndex);
980
- }
981
- } else {
982
- for (let i = Math.max(activeIndex - amount, 0); i <= Math.min(slideIndexLastInView + amount, len - 1); i += 1) {
983
- if (i !== activeIndex && (i > slideIndexLastInView || i < activeIndex)) {
984
- unlazy(swiper, i);
985
- }
986
- }
987
- }
988
- };
989
-
990
- function getActiveIndexByTranslate(swiper) {
991
- const {
992
- slidesGrid,
993
- params
994
- } = swiper;
995
- const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
996
- let activeIndex;
997
- for (let i = 0; i < slidesGrid.length; i += 1) {
998
- if (typeof slidesGrid[i + 1] !== 'undefined') {
999
- if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) {
1000
- activeIndex = i;
1001
- } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
1002
- activeIndex = i + 1;
1003
- }
1004
- } else if (translate >= slidesGrid[i]) {
1005
- activeIndex = i;
1006
- }
1007
- }
1008
- // Normalize slideIndex
1009
- if (params.normalizeSlideIndex) {
1010
- if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
1011
- }
1012
- return activeIndex;
1013
- }
1014
- function updateActiveIndex(newActiveIndex) {
1015
- const swiper = this;
1016
- const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
1017
- const {
1018
- snapGrid,
1019
- params,
1020
- activeIndex: previousIndex,
1021
- realIndex: previousRealIndex,
1022
- snapIndex: previousSnapIndex
1023
- } = swiper;
1024
- let activeIndex = newActiveIndex;
1025
- let snapIndex;
1026
- const getVirtualRealIndex = aIndex => {
1027
- let realIndex = aIndex - swiper.virtual.slidesBefore;
1028
- if (realIndex < 0) {
1029
- realIndex = swiper.virtual.slides.length + realIndex;
1030
- }
1031
- if (realIndex >= swiper.virtual.slides.length) {
1032
- realIndex -= swiper.virtual.slides.length;
1033
- }
1034
- return realIndex;
1035
- };
1036
- if (typeof activeIndex === 'undefined') {
1037
- activeIndex = getActiveIndexByTranslate(swiper);
1038
- }
1039
- if (snapGrid.indexOf(translate) >= 0) {
1040
- snapIndex = snapGrid.indexOf(translate);
1041
- } else {
1042
- const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
1043
- snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
1044
- }
1045
- if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
1046
- if (activeIndex === previousIndex && !swiper.params.loop) {
1047
- if (snapIndex !== previousSnapIndex) {
1048
- swiper.snapIndex = snapIndex;
1049
- swiper.emit('snapIndexChange');
1050
- }
1051
- return;
1052
- }
1053
- if (activeIndex === previousIndex && swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
1054
- swiper.realIndex = getVirtualRealIndex(activeIndex);
1055
- return;
1056
- }
1057
- const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
1058
-
1059
- // Get real index
1060
- let realIndex;
1061
- if (swiper.virtual && params.virtual.enabled) {
1062
- if (params.loop) {
1063
- realIndex = getVirtualRealIndex(activeIndex);
1064
- } else {
1065
- realIndex = activeIndex;
1066
- }
1067
- } else if (gridEnabled) {
1068
- const firstSlideInColumn = swiper.slides.find(slideEl => slideEl.column === activeIndex);
1069
- let activeSlideIndex = parseInt(firstSlideInColumn.getAttribute('data-swiper-slide-index'), 10);
1070
- if (Number.isNaN(activeSlideIndex)) {
1071
- activeSlideIndex = Math.max(swiper.slides.indexOf(firstSlideInColumn), 0);
1072
- }
1073
- realIndex = Math.floor(activeSlideIndex / params.grid.rows);
1074
- } else if (swiper.slides[activeIndex]) {
1075
- const slideIndex = swiper.slides[activeIndex].getAttribute('data-swiper-slide-index');
1076
- if (slideIndex) {
1077
- realIndex = parseInt(slideIndex, 10);
1078
- } else {
1079
- realIndex = activeIndex;
1080
- }
1081
- } else {
1082
- realIndex = activeIndex;
1083
- }
1084
- Object.assign(swiper, {
1085
- previousSnapIndex,
1086
- snapIndex,
1087
- previousRealIndex,
1088
- realIndex,
1089
- previousIndex,
1090
- activeIndex
1091
- });
1092
- if (swiper.initialized) {
1093
- preload(swiper);
1094
- }
1095
- swiper.emit('activeIndexChange');
1096
- swiper.emit('snapIndexChange');
1097
- if (swiper.initialized || swiper.params.runCallbacksOnInit) {
1098
- if (previousRealIndex !== realIndex) {
1099
- swiper.emit('realIndexChange');
1100
- }
1101
- swiper.emit('slideChange');
1102
- }
1103
- }
1104
-
1105
- function updateClickedSlide(el, path) {
1106
- const swiper = this;
1107
- const params = swiper.params;
1108
- let slide = el.closest(`.${params.slideClass}, swiper-slide`);
1109
- if (!slide && swiper.isElement && path && path.length > 1 && path.includes(el)) {
1110
- [...path.slice(path.indexOf(el) + 1, path.length)].forEach(pathEl => {
1111
- if (!slide && pathEl.matches && pathEl.matches(`.${params.slideClass}, swiper-slide`)) {
1112
- slide = pathEl;
1113
- }
1114
- });
1115
- }
1116
- let slideFound = false;
1117
- let slideIndex;
1118
- if (slide) {
1119
- for (let i = 0; i < swiper.slides.length; i += 1) {
1120
- if (swiper.slides[i] === slide) {
1121
- slideFound = true;
1122
- slideIndex = i;
1123
- break;
1124
- }
1125
- }
1126
- }
1127
- if (slide && slideFound) {
1128
- swiper.clickedSlide = slide;
1129
- if (swiper.virtual && swiper.params.virtual.enabled) {
1130
- swiper.clickedIndex = parseInt(slide.getAttribute('data-swiper-slide-index'), 10);
1131
- } else {
1132
- swiper.clickedIndex = slideIndex;
1133
- }
1134
- } else {
1135
- swiper.clickedSlide = undefined;
1136
- swiper.clickedIndex = undefined;
1137
- return;
1138
- }
1139
- if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
1140
- swiper.slideToClickedSlide();
1141
- }
1142
- }
1143
-
1144
- var update = {
1145
- updateSize,
1146
- updateSlides,
1147
- updateAutoHeight,
1148
- updateSlidesOffset,
1149
- updateSlidesProgress,
1150
- updateProgress,
1151
- updateSlidesClasses,
1152
- updateActiveIndex,
1153
- updateClickedSlide
1154
- };
1155
-
1156
- function getSwiperTranslate(axis = this.isHorizontal() ? 'x' : 'y') {
1157
- const swiper = this;
1158
- const {
1159
- params,
1160
- rtlTranslate: rtl,
1161
- translate,
1162
- wrapperEl
1163
- } = swiper;
1164
- if (params.virtualTranslate) {
1165
- return rtl ? -translate : translate;
1166
- }
1167
- if (params.cssMode) {
1168
- return translate;
1169
- }
1170
- let currentTranslate = utils.l(wrapperEl, axis);
1171
- currentTranslate += swiper.cssOverflowAdjustment();
1172
- if (rtl) currentTranslate = -currentTranslate;
1173
- return currentTranslate || 0;
1174
- }
1175
-
1176
- function setTranslate(translate, byController) {
1177
- const swiper = this;
1178
- const {
1179
- rtlTranslate: rtl,
1180
- params,
1181
- wrapperEl,
1182
- progress
1183
- } = swiper;
1184
- let x = 0;
1185
- let y = 0;
1186
- const z = 0;
1187
- if (swiper.isHorizontal()) {
1188
- x = rtl ? -translate : translate;
1189
- } else {
1190
- y = translate;
1191
- }
1192
- if (params.roundLengths) {
1193
- x = Math.floor(x);
1194
- y = Math.floor(y);
1195
- }
1196
- swiper.previousTranslate = swiper.translate;
1197
- swiper.translate = swiper.isHorizontal() ? x : y;
1198
- if (params.cssMode) {
1199
- wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
1200
- } else if (!params.virtualTranslate) {
1201
- if (swiper.isHorizontal()) {
1202
- x -= swiper.cssOverflowAdjustment();
1203
- } else {
1204
- y -= swiper.cssOverflowAdjustment();
1205
- }
1206
- wrapperEl.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
1207
- }
1208
-
1209
- // Check if we need to update progress
1210
- let newProgress;
1211
- const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
1212
- if (translatesDiff === 0) {
1213
- newProgress = 0;
1214
- } else {
1215
- newProgress = (translate - swiper.minTranslate()) / translatesDiff;
1216
- }
1217
- if (newProgress !== progress) {
1218
- swiper.updateProgress(translate);
1219
- }
1220
- swiper.emit('setTranslate', swiper.translate, byController);
1221
- }
1222
-
1223
- function minTranslate() {
1224
- return -this.snapGrid[0];
1225
- }
1226
-
1227
- function maxTranslate() {
1228
- return -this.snapGrid[this.snapGrid.length - 1];
1229
- }
1230
-
1231
- function translateTo(translate = 0, speed = this.params.speed, runCallbacks = true, translateBounds = true, internal) {
1232
- const swiper = this;
1233
- const {
1234
- params,
1235
- wrapperEl
1236
- } = swiper;
1237
- if (swiper.animating && params.preventInteractionOnTransition) {
1238
- return false;
1239
- }
1240
- const minTranslate = swiper.minTranslate();
1241
- const maxTranslate = swiper.maxTranslate();
1242
- let newTranslate;
1243
- if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate;
1244
-
1245
- // Update progress
1246
- swiper.updateProgress(newTranslate);
1247
- if (params.cssMode) {
1248
- const isH = swiper.isHorizontal();
1249
- if (speed === 0) {
1250
- wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
1251
- } else {
1252
- if (!swiper.support.smoothScroll) {
1253
- utils.u({
1254
- swiper,
1255
- targetPosition: -newTranslate,
1256
- side: isH ? 'left' : 'top'
1257
- });
1258
- return true;
1259
- }
1260
- wrapperEl.scrollTo({
1261
- [isH ? 'left' : 'top']: -newTranslate,
1262
- behavior: 'smooth'
1263
- });
1264
- }
1265
- return true;
1266
- }
1267
- if (speed === 0) {
1268
- swiper.setTransition(0);
1269
- swiper.setTranslate(newTranslate);
1270
- if (runCallbacks) {
1271
- swiper.emit('beforeTransitionStart', speed, internal);
1272
- swiper.emit('transitionEnd');
1273
- }
1274
- } else {
1275
- swiper.setTransition(speed);
1276
- swiper.setTranslate(newTranslate);
1277
- if (runCallbacks) {
1278
- swiper.emit('beforeTransitionStart', speed, internal);
1279
- swiper.emit('transitionStart');
1280
- }
1281
- if (!swiper.animating) {
1282
- swiper.animating = true;
1283
- if (!swiper.onTranslateToWrapperTransitionEnd) {
1284
- swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
1285
- if (!swiper || swiper.destroyed) return;
1286
- if (e.target !== this) return;
1287
- swiper.wrapperEl.removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
1288
- swiper.onTranslateToWrapperTransitionEnd = null;
1289
- delete swiper.onTranslateToWrapperTransitionEnd;
1290
- swiper.animating = false;
1291
- if (runCallbacks) {
1292
- swiper.emit('transitionEnd');
1293
- }
1294
- };
1295
- }
1296
- swiper.wrapperEl.addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
1297
- }
1298
- }
1299
- return true;
1300
- }
1301
-
1302
- var translate = {
1303
- getTranslate: getSwiperTranslate,
1304
- setTranslate,
1305
- minTranslate,
1306
- maxTranslate,
1307
- translateTo
1308
- };
1309
-
1310
- function setTransition(duration, byController) {
1311
- const swiper = this;
1312
- if (!swiper.params.cssMode) {
1313
- swiper.wrapperEl.style.transitionDuration = `${duration}ms`;
1314
- swiper.wrapperEl.style.transitionDelay = duration === 0 ? `0ms` : '';
1315
- }
1316
- swiper.emit('setTransition', duration, byController);
1317
- }
1318
-
1319
- function transitionEmit({
1320
- swiper,
1321
- runCallbacks,
1322
- direction,
1323
- step
1324
- }) {
1325
- const {
1326
- activeIndex,
1327
- previousIndex
1328
- } = swiper;
1329
- let dir = direction;
1330
- if (!dir) {
1331
- if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset';
1332
- }
1333
- swiper.emit(`transition${step}`);
1334
- if (runCallbacks && dir === 'reset') {
1335
- swiper.emit(`slideResetTransition${step}`);
1336
- } else if (runCallbacks && activeIndex !== previousIndex) {
1337
- swiper.emit(`slideChangeTransition${step}`);
1338
- if (dir === 'next') {
1339
- swiper.emit(`slideNextTransition${step}`);
1340
- } else {
1341
- swiper.emit(`slidePrevTransition${step}`);
1342
- }
1343
- }
1344
- }
1345
-
1346
- function transitionStart(runCallbacks = true, direction) {
1347
- const swiper = this;
1348
- const {
1349
- params
1350
- } = swiper;
1351
- if (params.cssMode) return;
1352
- if (params.autoHeight) {
1353
- swiper.updateAutoHeight();
1354
- }
1355
- transitionEmit({
1356
- swiper,
1357
- runCallbacks,
1358
- direction,
1359
- step: 'Start'
1360
- });
1361
- }
1362
-
1363
- function transitionEnd(runCallbacks = true, direction) {
1364
- const swiper = this;
1365
- const {
1366
- params
1367
- } = swiper;
1368
- swiper.animating = false;
1369
- if (params.cssMode) return;
1370
- swiper.setTransition(0);
1371
- transitionEmit({
1372
- swiper,
1373
- runCallbacks,
1374
- direction,
1375
- step: 'End'
1376
- });
1377
- }
1378
-
1379
- var transition = {
1380
- setTransition,
1381
- transitionStart,
1382
- transitionEnd
1383
- };
1384
-
1385
- function slideTo(index = 0, speed, runCallbacks = true, internal, initial) {
1386
- if (typeof index === 'string') {
1387
- index = parseInt(index, 10);
1388
- }
1389
- const swiper = this;
1390
- let slideIndex = index;
1391
- if (slideIndex < 0) slideIndex = 0;
1392
- const {
1393
- params,
1394
- snapGrid,
1395
- slidesGrid,
1396
- previousIndex,
1397
- activeIndex,
1398
- rtlTranslate: rtl,
1399
- wrapperEl,
1400
- enabled
1401
- } = swiper;
1402
- if (!enabled && !internal && !initial || swiper.destroyed || swiper.animating && params.preventInteractionOnTransition) {
1403
- return false;
1404
- }
1405
- if (typeof speed === 'undefined') {
1406
- speed = swiper.params.speed;
1407
- }
1408
- const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
1409
- let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
1410
- if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
1411
- const translate = -snapGrid[snapIndex];
1412
- // Normalize slideIndex
1413
- if (params.normalizeSlideIndex) {
1414
- for (let i = 0; i < slidesGrid.length; i += 1) {
1415
- const normalizedTranslate = -Math.floor(translate * 100);
1416
- const normalizedGrid = Math.floor(slidesGrid[i] * 100);
1417
- const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100);
1418
- if (typeof slidesGrid[i + 1] !== 'undefined') {
1419
- if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) {
1420
- slideIndex = i;
1421
- } else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) {
1422
- slideIndex = i + 1;
1423
- }
1424
- } else if (normalizedTranslate >= normalizedGrid) {
1425
- slideIndex = i;
1426
- }
1427
- }
1428
- }
1429
- // Directions locks
1430
- if (swiper.initialized && slideIndex !== activeIndex) {
1431
- if (!swiper.allowSlideNext && (rtl ? translate > swiper.translate && translate > swiper.minTranslate() : translate < swiper.translate && translate < swiper.minTranslate())) {
1432
- return false;
1433
- }
1434
- if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
1435
- if ((activeIndex || 0) !== slideIndex) {
1436
- return false;
1437
- }
1438
- }
1439
- }
1440
- if (slideIndex !== (previousIndex || 0) && runCallbacks) {
1441
- swiper.emit('beforeSlideChangeStart');
1442
- }
1443
-
1444
- // Update progress
1445
- swiper.updateProgress(translate);
1446
- let direction;
1447
- if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset';
1448
-
1449
- // initial virtual
1450
- const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
1451
- const isInitialVirtual = isVirtual && initial;
1452
- // Update Index
1453
- if (!isInitialVirtual && (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate)) {
1454
- swiper.updateActiveIndex(slideIndex);
1455
- // Update Height
1456
- if (params.autoHeight) {
1457
- swiper.updateAutoHeight();
1458
- }
1459
- swiper.updateSlidesClasses();
1460
- if (params.effect !== 'slide') {
1461
- swiper.setTranslate(translate);
1462
- }
1463
- if (direction !== 'reset') {
1464
- swiper.transitionStart(runCallbacks, direction);
1465
- swiper.transitionEnd(runCallbacks, direction);
1466
- }
1467
- return false;
1468
- }
1469
- if (params.cssMode) {
1470
- const isH = swiper.isHorizontal();
1471
- const t = rtl ? translate : -translate;
1472
- if (speed === 0) {
1473
- if (isVirtual) {
1474
- swiper.wrapperEl.style.scrollSnapType = 'none';
1475
- swiper._immediateVirtual = true;
1476
- }
1477
- if (isVirtual && !swiper._cssModeVirtualInitialSet && swiper.params.initialSlide > 0) {
1478
- swiper._cssModeVirtualInitialSet = true;
1479
- requestAnimationFrame(() => {
1480
- wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
1481
- });
1482
- } else {
1483
- wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
1484
- }
1485
- if (isVirtual) {
1486
- requestAnimationFrame(() => {
1487
- swiper.wrapperEl.style.scrollSnapType = '';
1488
- swiper._immediateVirtual = false;
1489
- });
1490
- }
1491
- } else {
1492
- if (!swiper.support.smoothScroll) {
1493
- utils.u({
1494
- swiper,
1495
- targetPosition: t,
1496
- side: isH ? 'left' : 'top'
1497
- });
1498
- return true;
1499
- }
1500
- wrapperEl.scrollTo({
1501
- [isH ? 'left' : 'top']: t,
1502
- behavior: 'smooth'
1503
- });
1504
- }
1505
- return true;
1506
- }
1507
- const browser = getBrowser();
1508
- const isSafari = browser.isSafari;
1509
- if (isVirtual && !initial && isSafari && swiper.isElement) {
1510
- swiper.virtual.update(false, false, slideIndex);
1511
- }
1512
- swiper.setTransition(speed);
1513
- swiper.setTranslate(translate);
1514
- swiper.updateActiveIndex(slideIndex);
1515
- swiper.updateSlidesClasses();
1516
- swiper.emit('beforeTransitionStart', speed, internal);
1517
- swiper.transitionStart(runCallbacks, direction);
1518
- if (speed === 0) {
1519
- swiper.transitionEnd(runCallbacks, direction);
1520
- } else if (!swiper.animating) {
1521
- swiper.animating = true;
1522
- if (!swiper.onSlideToWrapperTransitionEnd) {
1523
- swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
1524
- if (!swiper || swiper.destroyed) return;
1525
- if (e.target !== this) return;
1526
- swiper.wrapperEl.removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
1527
- swiper.onSlideToWrapperTransitionEnd = null;
1528
- delete swiper.onSlideToWrapperTransitionEnd;
1529
- swiper.transitionEnd(runCallbacks, direction);
1530
- };
1531
- }
1532
- swiper.wrapperEl.addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
1533
- }
1534
- return true;
1535
- }
1536
-
1537
- function slideToLoop(index = 0, speed, runCallbacks = true, internal) {
1538
- if (typeof index === 'string') {
1539
- const indexAsNumber = parseInt(index, 10);
1540
- index = indexAsNumber;
1541
- }
1542
- const swiper = this;
1543
- if (swiper.destroyed) return;
1544
- if (typeof speed === 'undefined') {
1545
- speed = swiper.params.speed;
1546
- }
1547
- const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
1548
- let newIndex = index;
1549
- if (swiper.params.loop) {
1550
- if (swiper.virtual && swiper.params.virtual.enabled) {
1551
- // eslint-disable-next-line
1552
- newIndex = newIndex + swiper.virtual.slidesBefore;
1553
- } else {
1554
- let targetSlideIndex;
1555
- if (gridEnabled) {
1556
- const slideIndex = newIndex * swiper.params.grid.rows;
1557
- targetSlideIndex = swiper.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex).column;
1558
- } else {
1559
- targetSlideIndex = swiper.getSlideIndexByData(newIndex);
1560
- }
1561
- const cols = gridEnabled ? Math.ceil(swiper.slides.length / swiper.params.grid.rows) : swiper.slides.length;
1562
- const {
1563
- centeredSlides,
1564
- slidesOffsetBefore,
1565
- slidesOffsetAfter
1566
- } = swiper.params;
1567
- const bothDirections = centeredSlides || !!slidesOffsetBefore || !!slidesOffsetAfter;
1568
- let slidesPerView = swiper.params.slidesPerView;
1569
- if (slidesPerView === 'auto') {
1570
- slidesPerView = swiper.slidesPerViewDynamic();
1571
- } else {
1572
- slidesPerView = Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
1573
- if (bothDirections && slidesPerView % 2 === 0) {
1574
- slidesPerView = slidesPerView + 1;
1575
- }
1576
- }
1577
- let needLoopFix = cols - targetSlideIndex < slidesPerView;
1578
- if (bothDirections) {
1579
- needLoopFix = needLoopFix || targetSlideIndex < Math.ceil(slidesPerView / 2);
1580
- }
1581
- if (internal && bothDirections && swiper.params.slidesPerView !== 'auto' && !gridEnabled) {
1582
- needLoopFix = false;
1583
- }
1584
- if (needLoopFix) {
1585
- const direction = bothDirections ? targetSlideIndex < swiper.activeIndex ? 'prev' : 'next' : targetSlideIndex - swiper.activeIndex - 1 < swiper.params.slidesPerView ? 'next' : 'prev';
1586
- swiper.loopFix({
1587
- direction,
1588
- slideTo: true,
1589
- activeSlideIndex: direction === 'next' ? targetSlideIndex + 1 : targetSlideIndex - cols + 1,
1590
- slideRealIndex: direction === 'next' ? swiper.realIndex : undefined
1591
- });
1592
- }
1593
- if (gridEnabled) {
1594
- const slideIndex = newIndex * swiper.params.grid.rows;
1595
- newIndex = swiper.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex).column;
1596
- } else {
1597
- newIndex = swiper.getSlideIndexByData(newIndex);
1598
- }
1599
- }
1600
- }
1601
- requestAnimationFrame(() => {
1602
- swiper.slideTo(newIndex, speed, runCallbacks, internal);
1603
- });
1604
- return swiper;
1605
- }
1606
-
1607
- /* eslint no-unused-vars: "off" */
1608
- function slideNext(speed, runCallbacks = true, internal) {
1609
- const swiper = this;
1610
- const {
1611
- enabled,
1612
- params,
1613
- animating
1614
- } = swiper;
1615
- if (!enabled || swiper.destroyed) return swiper;
1616
- if (typeof speed === 'undefined') {
1617
- speed = swiper.params.speed;
1618
- }
1619
- let perGroup = params.slidesPerGroup;
1620
- if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
1621
- perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
1622
- }
1623
- const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
1624
- const isVirtual = swiper.virtual && params.virtual.enabled;
1625
- if (params.loop) {
1626
- if (animating && !isVirtual && params.loopPreventsSliding) return false;
1627
- swiper.loopFix({
1628
- direction: 'next'
1629
- });
1630
- // eslint-disable-next-line
1631
- swiper._clientLeft = swiper.wrapperEl.clientLeft;
1632
- if (swiper.activeIndex === swiper.slides.length - 1 && params.cssMode) {
1633
- requestAnimationFrame(() => {
1634
- swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
1635
- });
1636
- return true;
1637
- }
1638
- }
1639
- if (params.rewind && swiper.isEnd) {
1640
- return swiper.slideTo(0, speed, runCallbacks, internal);
1641
- }
1642
- return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
1643
- }
1644
-
1645
- /* eslint no-unused-vars: "off" */
1646
- function slidePrev(speed, runCallbacks = true, internal) {
1647
- const swiper = this;
1648
- const {
1649
- params,
1650
- snapGrid,
1651
- slidesGrid,
1652
- rtlTranslate,
1653
- enabled,
1654
- animating
1655
- } = swiper;
1656
- if (!enabled || swiper.destroyed) return swiper;
1657
- if (typeof speed === 'undefined') {
1658
- speed = swiper.params.speed;
1659
- }
1660
- const isVirtual = swiper.virtual && params.virtual.enabled;
1661
- if (params.loop) {
1662
- if (animating && !isVirtual && params.loopPreventsSliding) return false;
1663
- swiper.loopFix({
1664
- direction: 'prev'
1665
- });
1666
- // eslint-disable-next-line
1667
- swiper._clientLeft = swiper.wrapperEl.clientLeft;
1668
- }
1669
- const translate = rtlTranslate ? swiper.translate : -swiper.translate;
1670
- function normalize(val) {
1671
- if (val < 0) return -Math.floor(Math.abs(val));
1672
- return Math.floor(val);
1673
- }
1674
- const normalizedTranslate = normalize(translate);
1675
- const normalizedSnapGrid = snapGrid.map(val => normalize(val));
1676
- const isFreeMode = params.freeMode && params.freeMode.enabled;
1677
- let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
1678
- if (typeof prevSnap === 'undefined' && (params.cssMode || isFreeMode)) {
1679
- let prevSnapIndex;
1680
- snapGrid.forEach((snap, snapIndex) => {
1681
- if (normalizedTranslate >= snap) {
1682
- // prevSnap = snap;
1683
- prevSnapIndex = snapIndex;
1684
- }
1685
- });
1686
- if (typeof prevSnapIndex !== 'undefined') {
1687
- prevSnap = isFreeMode ? snapGrid[prevSnapIndex] : snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
1688
- }
1689
- }
1690
- let prevIndex = 0;
1691
- if (typeof prevSnap !== 'undefined') {
1692
- prevIndex = slidesGrid.indexOf(prevSnap);
1693
- if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
1694
- if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
1695
- prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
1696
- prevIndex = Math.max(prevIndex, 0);
1697
- }
1698
- }
1699
- if (params.rewind && swiper.isBeginning) {
1700
- const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
1701
- return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
1702
- } else if (params.loop && swiper.activeIndex === 0 && params.cssMode) {
1703
- requestAnimationFrame(() => {
1704
- swiper.slideTo(prevIndex, speed, runCallbacks, internal);
1705
- });
1706
- return true;
1707
- }
1708
- return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
1709
- }
1710
-
1711
- /* eslint no-unused-vars: "off" */
1712
- function slideReset(speed, runCallbacks = true, internal) {
1713
- const swiper = this;
1714
- if (swiper.destroyed) return;
1715
- if (typeof speed === 'undefined') {
1716
- speed = swiper.params.speed;
1717
- }
1718
- return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
1719
- }
1720
-
1721
- /* eslint no-unused-vars: "off" */
1722
- function slideToClosest(speed, runCallbacks = true, internal, threshold = 0.5) {
1723
- const swiper = this;
1724
- if (swiper.destroyed) return;
1725
- if (typeof speed === 'undefined') {
1726
- speed = swiper.params.speed;
1727
- }
1728
- let index = swiper.activeIndex;
1729
- const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
1730
- const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
1731
- const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
1732
- if (translate >= swiper.snapGrid[snapIndex]) {
1733
- // The current translate is on or after the current snap index, so the choice
1734
- // is between the current index and the one after it.
1735
- const currentSnap = swiper.snapGrid[snapIndex];
1736
- const nextSnap = swiper.snapGrid[snapIndex + 1];
1737
- if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
1738
- index += swiper.params.slidesPerGroup;
1739
- }
1740
- } else {
1741
- // The current translate is before the current snap index, so the choice
1742
- // is between the current index and the one before it.
1743
- const prevSnap = swiper.snapGrid[snapIndex - 1];
1744
- const currentSnap = swiper.snapGrid[snapIndex];
1745
- if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
1746
- index -= swiper.params.slidesPerGroup;
1747
- }
1748
- }
1749
- index = Math.max(index, 0);
1750
- index = Math.min(index, swiper.slidesGrid.length - 1);
1751
- return swiper.slideTo(index, speed, runCallbacks, internal);
1752
- }
1753
-
1754
- function slideToClickedSlide() {
1755
- const swiper = this;
1756
- if (swiper.destroyed) return;
1757
- const {
1758
- params,
1759
- slidesEl
1760
- } = swiper;
1761
- const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
1762
- let slideToIndex = swiper.getSlideIndexWhenGrid(swiper.clickedIndex);
1763
- let realIndex;
1764
- const slideSelector = swiper.isElement ? `swiper-slide` : `.${params.slideClass}`;
1765
- const isGrid = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
1766
- if (params.loop) {
1767
- if (swiper.animating) return;
1768
- realIndex = parseInt(swiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10);
1769
- if (params.centeredSlides) {
1770
- swiper.slideToLoop(realIndex);
1771
- } else if (slideToIndex > (isGrid ? (swiper.slides.length - slidesPerView) / 2 - (swiper.params.grid.rows - 1) : swiper.slides.length - slidesPerView)) {
1772
- swiper.loopFix();
1773
- slideToIndex = swiper.getSlideIndex(utils.e(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
1774
- utils.n(() => {
1775
- swiper.slideTo(slideToIndex);
1776
- });
1777
- } else {
1778
- swiper.slideTo(slideToIndex);
1779
- }
1780
- } else {
1781
- swiper.slideTo(slideToIndex);
1782
- }
1783
- }
1784
-
1785
- var slide = {
1786
- slideTo,
1787
- slideToLoop,
1788
- slideNext,
1789
- slidePrev,
1790
- slideReset,
1791
- slideToClosest,
1792
- slideToClickedSlide
1793
- };
1794
-
1795
- function loopCreate(slideRealIndex, initial) {
1796
- const swiper = this;
1797
- const {
1798
- params,
1799
- slidesEl
1800
- } = swiper;
1801
- if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
1802
- const initSlides = () => {
1803
- const slides = utils.e(slidesEl, `.${params.slideClass}, swiper-slide`);
1804
- slides.forEach((el, index) => {
1805
- el.setAttribute('data-swiper-slide-index', index);
1806
- });
1807
- };
1808
- const clearBlankSlides = () => {
1809
- const slides = utils.e(slidesEl, `.${params.slideBlankClass}`);
1810
- slides.forEach(el => {
1811
- el.remove();
1812
- });
1813
- if (slides.length > 0) {
1814
- swiper.recalcSlides();
1815
- swiper.updateSlides();
1816
- }
1817
- };
1818
- const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
1819
- if (params.loopAddBlankSlides && (params.slidesPerGroup > 1 || gridEnabled)) {
1820
- clearBlankSlides();
1821
- }
1822
- const slidesPerGroup = params.slidesPerGroup * (gridEnabled ? params.grid.rows : 1);
1823
- const shouldFillGroup = swiper.slides.length % slidesPerGroup !== 0;
1824
- const shouldFillGrid = gridEnabled && swiper.slides.length % params.grid.rows !== 0;
1825
- const addBlankSlides = amountOfSlides => {
1826
- for (let i = 0; i < amountOfSlides; i += 1) {
1827
- const slideEl = swiper.isElement ? utils.c('swiper-slide', [params.slideBlankClass]) : utils.c('div', [params.slideClass, params.slideBlankClass]);
1828
- swiper.slidesEl.append(slideEl);
1829
- }
1830
- };
1831
- if (shouldFillGroup) {
1832
- if (params.loopAddBlankSlides) {
1833
- const slidesToAdd = slidesPerGroup - swiper.slides.length % slidesPerGroup;
1834
- addBlankSlides(slidesToAdd);
1835
- swiper.recalcSlides();
1836
- swiper.updateSlides();
1837
- } else {
1838
- utils.v('Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
1839
- }
1840
- initSlides();
1841
- } else if (shouldFillGrid) {
1842
- if (params.loopAddBlankSlides) {
1843
- const slidesToAdd = params.grid.rows - swiper.slides.length % params.grid.rows;
1844
- addBlankSlides(slidesToAdd);
1845
- swiper.recalcSlides();
1846
- swiper.updateSlides();
1847
- } else {
1848
- utils.v('Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
1849
- }
1850
- initSlides();
1851
- } else {
1852
- initSlides();
1853
- }
1854
- const bothDirections = params.centeredSlides || !!params.slidesOffsetBefore || !!params.slidesOffsetAfter;
1855
- swiper.loopFix({
1856
- slideRealIndex,
1857
- direction: bothDirections ? undefined : 'next',
1858
- initial
1859
- });
1860
- }
1861
-
1862
- function loopFix({
1863
- slideRealIndex,
1864
- slideTo = true,
1865
- direction,
1866
- setTranslate,
1867
- activeSlideIndex,
1868
- initial,
1869
- byController,
1870
- byMousewheel
1871
- } = {}) {
1872
- const swiper = this;
1873
- if (!swiper.params.loop) return;
1874
- swiper.emit('beforeLoopFix');
1875
- const {
1876
- slides,
1877
- allowSlidePrev,
1878
- allowSlideNext,
1879
- slidesEl,
1880
- params
1881
- } = swiper;
1882
- const {
1883
- centeredSlides,
1884
- slidesOffsetBefore,
1885
- slidesOffsetAfter,
1886
- initialSlide
1887
- } = params;
1888
- const bothDirections = centeredSlides || !!slidesOffsetBefore || !!slidesOffsetAfter;
1889
- swiper.allowSlidePrev = true;
1890
- swiper.allowSlideNext = true;
1891
- if (swiper.virtual && params.virtual.enabled) {
1892
- if (slideTo) {
1893
- if (!bothDirections && swiper.snapIndex === 0) {
1894
- swiper.slideTo(swiper.virtual.slides.length, 0, false, true);
1895
- } else if (bothDirections && swiper.snapIndex < params.slidesPerView) {
1896
- swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true);
1897
- } else if (swiper.snapIndex === swiper.snapGrid.length - 1) {
1898
- swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true);
1899
- }
1900
- }
1901
- swiper.allowSlidePrev = allowSlidePrev;
1902
- swiper.allowSlideNext = allowSlideNext;
1903
- swiper.emit('loopFix');
1904
- return;
1905
- }
1906
- let slidesPerView = params.slidesPerView;
1907
- if (slidesPerView === 'auto') {
1908
- slidesPerView = swiper.slidesPerViewDynamic();
1909
- } else {
1910
- slidesPerView = Math.ceil(parseFloat(params.slidesPerView, 10));
1911
- if (bothDirections && slidesPerView % 2 === 0) {
1912
- slidesPerView = slidesPerView + 1;
1913
- }
1914
- }
1915
- const slidesPerGroup = params.slidesPerGroupAuto ? slidesPerView : params.slidesPerGroup;
1916
- let loopedSlides = bothDirections ? Math.max(slidesPerGroup, Math.ceil(slidesPerView / 2)) : slidesPerGroup;
1917
- if (loopedSlides % slidesPerGroup !== 0) {
1918
- loopedSlides += slidesPerGroup - loopedSlides % slidesPerGroup;
1919
- }
1920
- loopedSlides += params.loopAdditionalSlides;
1921
- swiper.loopedSlides = loopedSlides;
1922
- const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
1923
- if (slides.length < slidesPerView + loopedSlides || swiper.params.effect === 'cards' && slides.length < slidesPerView + loopedSlides * 2) {
1924
- utils.v('Swiper Loop Warning: The number of slides is not enough for loop mode, it will be disabled or not function properly. You need to add more slides (or make duplicates) or lower the values of slidesPerView and slidesPerGroup parameters');
1925
- } else if (gridEnabled && params.grid.fill === 'row') {
1926
- utils.v('Swiper Loop Warning: Loop mode is not compatible with grid.fill = `row`');
1927
- }
1928
- const prependSlidesIndexes = [];
1929
- const appendSlidesIndexes = [];
1930
- const cols = gridEnabled ? Math.ceil(slides.length / params.grid.rows) : slides.length;
1931
- const isInitialOverflow = initial && cols - initialSlide < slidesPerView && !bothDirections;
1932
- let activeIndex = isInitialOverflow ? initialSlide : swiper.activeIndex;
1933
- if (typeof activeSlideIndex === 'undefined') {
1934
- activeSlideIndex = swiper.getSlideIndex(slides.find(el => el.classList.contains(params.slideActiveClass)));
1935
- } else {
1936
- activeIndex = activeSlideIndex;
1937
- }
1938
- const isNext = direction === 'next' || !direction;
1939
- const isPrev = direction === 'prev' || !direction;
1940
- let slidesPrepended = 0;
1941
- let slidesAppended = 0;
1942
- const activeColIndex = gridEnabled ? slides[activeSlideIndex].column : activeSlideIndex;
1943
- const activeColIndexWithShift = activeColIndex + (bothDirections && typeof setTranslate === 'undefined' ? -slidesPerView / 2 + 0.5 : 0);
1944
- // prepend last slides before start
1945
- if (activeColIndexWithShift < loopedSlides) {
1946
- slidesPrepended = Math.max(loopedSlides - activeColIndexWithShift, slidesPerGroup);
1947
- for (let i = 0; i < loopedSlides - activeColIndexWithShift; i += 1) {
1948
- const index = i - Math.floor(i / cols) * cols;
1949
- if (gridEnabled) {
1950
- const colIndexToPrepend = cols - index - 1;
1951
- for (let i = slides.length - 1; i >= 0; i -= 1) {
1952
- if (slides[i].column === colIndexToPrepend) prependSlidesIndexes.push(i);
1953
- }
1954
- // slides.forEach((slide, slideIndex) => {
1955
- // if (slide.column === colIndexToPrepend) prependSlidesIndexes.push(slideIndex);
1956
- // });
1957
- } else {
1958
- prependSlidesIndexes.push(cols - index - 1);
1959
- }
1960
- }
1961
- } else if (activeColIndexWithShift + slidesPerView > cols - loopedSlides) {
1962
- slidesAppended = Math.max(activeColIndexWithShift - (cols - loopedSlides * 2), slidesPerGroup);
1963
- if (isInitialOverflow) {
1964
- slidesAppended = Math.max(slidesAppended, slidesPerView - cols + initialSlide + 1);
1965
- }
1966
- for (let i = 0; i < slidesAppended; i += 1) {
1967
- const index = i - Math.floor(i / cols) * cols;
1968
- if (gridEnabled) {
1969
- slides.forEach((slide, slideIndex) => {
1970
- if (slide.column === index) appendSlidesIndexes.push(slideIndex);
1971
- });
1972
- } else {
1973
- appendSlidesIndexes.push(index);
1974
- }
1975
- }
1976
- }
1977
- swiper.__preventObserver__ = true;
1978
- requestAnimationFrame(() => {
1979
- swiper.__preventObserver__ = false;
1980
- });
1981
- if (swiper.params.effect === 'cards' && slides.length < slidesPerView + loopedSlides * 2) {
1982
- if (appendSlidesIndexes.includes(activeSlideIndex)) {
1983
- appendSlidesIndexes.splice(appendSlidesIndexes.indexOf(activeSlideIndex), 1);
1984
- }
1985
- if (prependSlidesIndexes.includes(activeSlideIndex)) {
1986
- prependSlidesIndexes.splice(prependSlidesIndexes.indexOf(activeSlideIndex), 1);
1987
- }
1988
- }
1989
- if (isPrev) {
1990
- prependSlidesIndexes.forEach(index => {
1991
- slides[index].swiperLoopMoveDOM = true;
1992
- slidesEl.prepend(slides[index]);
1993
- slides[index].swiperLoopMoveDOM = false;
1994
- });
1995
- }
1996
- if (isNext) {
1997
- appendSlidesIndexes.forEach(index => {
1998
- slides[index].swiperLoopMoveDOM = true;
1999
- slidesEl.append(slides[index]);
2000
- slides[index].swiperLoopMoveDOM = false;
2001
- });
2002
- }
2003
- swiper.recalcSlides();
2004
- if (params.slidesPerView === 'auto') {
2005
- swiper.updateSlides();
2006
- } else if (gridEnabled && (prependSlidesIndexes.length > 0 && isPrev || appendSlidesIndexes.length > 0 && isNext)) {
2007
- swiper.slides.forEach((slide, slideIndex) => {
2008
- swiper.grid.updateSlide(slideIndex, slide, swiper.slides);
2009
- });
2010
- }
2011
- if (params.watchSlidesProgress) {
2012
- swiper.updateSlidesOffset();
2013
- }
2014
- if (slideTo) {
2015
- if (prependSlidesIndexes.length > 0 && isPrev) {
2016
- if (typeof slideRealIndex === 'undefined') {
2017
- const currentSlideTranslate = swiper.slidesGrid[activeIndex];
2018
- const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended];
2019
- const diff = newSlideTranslate - currentSlideTranslate;
2020
- if (byMousewheel) {
2021
- swiper.setTranslate(swiper.translate - diff);
2022
- } else {
2023
- swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
2024
- if (setTranslate) {
2025
- swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
2026
- swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
2027
- }
2028
- }
2029
- } else {
2030
- if (setTranslate) {
2031
- const shift = gridEnabled ? prependSlidesIndexes.length / params.grid.rows : prependSlidesIndexes.length;
2032
- swiper.slideTo(swiper.activeIndex + shift, 0, false, true);
2033
- swiper.touchEventsData.currentTranslate = swiper.translate;
2034
- }
2035
- }
2036
- } else if (appendSlidesIndexes.length > 0 && isNext) {
2037
- if (typeof slideRealIndex === 'undefined') {
2038
- const currentSlideTranslate = swiper.slidesGrid[activeIndex];
2039
- const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended];
2040
- const diff = newSlideTranslate - currentSlideTranslate;
2041
- if (byMousewheel) {
2042
- swiper.setTranslate(swiper.translate - diff);
2043
- } else {
2044
- swiper.slideTo(activeIndex - slidesAppended, 0, false, true);
2045
- if (setTranslate) {
2046
- swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
2047
- swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
2048
- }
2049
- }
2050
- } else {
2051
- const shift = gridEnabled ? appendSlidesIndexes.length / params.grid.rows : appendSlidesIndexes.length;
2052
- swiper.slideTo(swiper.activeIndex - shift, 0, false, true);
2053
- }
2054
- }
2055
- }
2056
- swiper.allowSlidePrev = allowSlidePrev;
2057
- swiper.allowSlideNext = allowSlideNext;
2058
- if (swiper.controller && swiper.controller.control && !byController) {
2059
- const loopParams = {
2060
- slideRealIndex,
2061
- direction,
2062
- setTranslate,
2063
- activeSlideIndex,
2064
- byController: true
2065
- };
2066
- if (Array.isArray(swiper.controller.control)) {
2067
- swiper.controller.control.forEach(c => {
2068
- if (!c.destroyed && c.params.loop) c.loopFix({
2069
- ...loopParams,
2070
- slideTo: c.params.slidesPerView === params.slidesPerView ? slideTo : false
2071
- });
2072
- });
2073
- } else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) {
2074
- swiper.controller.control.loopFix({
2075
- ...loopParams,
2076
- slideTo: swiper.controller.control.params.slidesPerView === params.slidesPerView ? slideTo : false
2077
- });
2078
- }
2079
- }
2080
- swiper.emit('loopFix');
2081
- }
2082
-
2083
- function loopDestroy() {
2084
- const swiper = this;
2085
- const {
2086
- params,
2087
- slidesEl
2088
- } = swiper;
2089
- if (!params.loop || !slidesEl || swiper.virtual && swiper.params.virtual.enabled) return;
2090
- swiper.recalcSlides();
2091
- const newSlidesOrder = [];
2092
- swiper.slides.forEach(slideEl => {
2093
- const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex;
2094
- newSlidesOrder[index] = slideEl;
2095
- });
2096
- swiper.slides.forEach(slideEl => {
2097
- slideEl.removeAttribute('data-swiper-slide-index');
2098
- });
2099
- newSlidesOrder.forEach(slideEl => {
2100
- slidesEl.append(slideEl);
2101
- });
2102
- swiper.recalcSlides();
2103
- swiper.slideTo(swiper.realIndex, 0);
2104
- }
2105
-
2106
- var loop = {
2107
- loopCreate,
2108
- loopFix,
2109
- loopDestroy
2110
- };
2111
-
2112
- function setGrabCursor(moving) {
2113
- const swiper = this;
2114
- if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
2115
- const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
2116
- if (swiper.isElement) {
2117
- swiper.__preventObserver__ = true;
2118
- }
2119
- el.style.cursor = 'move';
2120
- el.style.cursor = moving ? 'grabbing' : 'grab';
2121
- if (swiper.isElement) {
2122
- requestAnimationFrame(() => {
2123
- swiper.__preventObserver__ = false;
2124
- });
2125
- }
2126
- }
2127
-
2128
- function unsetGrabCursor() {
2129
- const swiper = this;
2130
- if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
2131
- return;
2132
- }
2133
- if (swiper.isElement) {
2134
- swiper.__preventObserver__ = true;
2135
- }
2136
- swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
2137
- if (swiper.isElement) {
2138
- requestAnimationFrame(() => {
2139
- swiper.__preventObserver__ = false;
2140
- });
2141
- }
2142
- }
2143
-
2144
- var grabCursor = {
2145
- setGrabCursor,
2146
- unsetGrabCursor
2147
- };
2148
-
2149
- // Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
2150
- function closestElement(selector, base = this) {
2151
- function __closestFrom(el) {
2152
- if (!el || el === ssrWindow_esm.g() || el === ssrWindow_esm.a()) return null;
2153
- if (el.assignedSlot) el = el.assignedSlot;
2154
- const found = el.closest(selector);
2155
- if (!found && !el.getRootNode) {
2156
- return null;
2157
- }
2158
- return found || __closestFrom(el.getRootNode().host);
2159
- }
2160
- return __closestFrom(base);
2161
- }
2162
- function preventEdgeSwipe(swiper, event, startX) {
2163
- const window = ssrWindow_esm.a();
2164
- const {
2165
- params
2166
- } = swiper;
2167
- const edgeSwipeDetection = params.edgeSwipeDetection;
2168
- const edgeSwipeThreshold = params.edgeSwipeThreshold;
2169
- if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
2170
- if (edgeSwipeDetection === 'prevent') {
2171
- event.preventDefault();
2172
- return true;
2173
- }
2174
- return false;
2175
- }
2176
- return true;
2177
- }
2178
- function onTouchStart(event) {
2179
- const swiper = this;
2180
- const document = ssrWindow_esm.g();
2181
- let e = event;
2182
- if (e.originalEvent) e = e.originalEvent;
2183
- const data = swiper.touchEventsData;
2184
- if (e.type === 'pointerdown') {
2185
- if (data.pointerId !== null && data.pointerId !== e.pointerId) {
2186
- return;
2187
- }
2188
- data.pointerId = e.pointerId;
2189
- } else if (e.type === 'touchstart' && e.targetTouches.length === 1) {
2190
- data.touchId = e.targetTouches[0].identifier;
2191
- }
2192
- if (e.type === 'touchstart') {
2193
- // don't proceed touch event
2194
- preventEdgeSwipe(swiper, e, e.targetTouches[0].pageX);
2195
- return;
2196
- }
2197
- const {
2198
- params,
2199
- touches,
2200
- enabled
2201
- } = swiper;
2202
- if (!enabled) return;
2203
- if (!params.simulateTouch && e.pointerType === 'mouse') return;
2204
- if (swiper.animating && params.preventInteractionOnTransition) {
2205
- return;
2206
- }
2207
- if (!swiper.animating && params.cssMode && params.loop) {
2208
- swiper.loopFix();
2209
- }
2210
- let targetEl = e.target;
2211
- if (params.touchEventsTarget === 'wrapper') {
2212
- if (!utils.w(targetEl, swiper.wrapperEl)) return;
2213
- }
2214
- if ('which' in e && e.which === 3) return;
2215
- if ('button' in e && e.button > 0) return;
2216
- if (data.isTouched && data.isMoved) return;
2217
-
2218
- // change target el for shadow root component
2219
- const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== '';
2220
- // eslint-disable-next-line
2221
- const eventPath = e.composedPath ? e.composedPath() : e.path;
2222
- if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) {
2223
- targetEl = eventPath[0];
2224
- }
2225
- const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
2226
- const isTargetShadow = !!(e.target && e.target.shadowRoot);
2227
-
2228
- // use closestElement for shadow root element to get the actual closest for nested shadow root element
2229
- if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) {
2230
- swiper.allowClick = true;
2231
- return;
2232
- }
2233
- if (params.swipeHandler) {
2234
- if (!targetEl.closest(params.swipeHandler)) return;
2235
- }
2236
- touches.currentX = e.pageX;
2237
- touches.currentY = e.pageY;
2238
- const startX = touches.currentX;
2239
- const startY = touches.currentY;
2240
-
2241
- // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore
2242
-
2243
- if (!preventEdgeSwipe(swiper, e, startX)) {
2244
- return;
2245
- }
2246
- Object.assign(data, {
2247
- isTouched: true,
2248
- isMoved: false,
2249
- allowTouchCallbacks: true,
2250
- isScrolling: undefined,
2251
- startMoving: undefined
2252
- });
2253
- touches.startX = startX;
2254
- touches.startY = startY;
2255
- data.touchStartTime = utils.h();
2256
- swiper.allowClick = true;
2257
- swiper.updateSize();
2258
- swiper.swipeDirection = undefined;
2259
- if (params.threshold > 0) data.allowThresholdMove = false;
2260
- let preventDefault = true;
2261
- if (targetEl.matches(data.focusableElements)) {
2262
- preventDefault = false;
2263
- if (targetEl.nodeName === 'SELECT') {
2264
- data.isTouched = false;
2265
- }
2266
- }
2267
- if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl && (e.pointerType === 'mouse' || e.pointerType !== 'mouse' && !targetEl.matches(data.focusableElements))) {
2268
- document.activeElement.blur();
2269
- }
2270
- const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
2271
- if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) {
2272
- e.preventDefault();
2273
- }
2274
- if (params.freeMode && params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
2275
- swiper.freeMode.onTouchStart();
2276
- }
2277
- swiper.emit('touchStart', e);
2278
- }
2279
-
2280
- function onTouchMove(event) {
2281
- const document = ssrWindow_esm.g();
2282
- const swiper = this;
2283
- const data = swiper.touchEventsData;
2284
- const {
2285
- params,
2286
- touches,
2287
- rtlTranslate: rtl,
2288
- enabled
2289
- } = swiper;
2290
- if (!enabled) return;
2291
- if (!params.simulateTouch && event.pointerType === 'mouse') return;
2292
- let e = event;
2293
- if (e.originalEvent) e = e.originalEvent;
2294
- if (e.type === 'pointermove') {
2295
- if (data.touchId !== null) return; // return from pointer if we use touch
2296
- const id = e.pointerId;
2297
- if (id !== data.pointerId) return;
2298
- }
2299
- let targetTouch;
2300
- if (e.type === 'touchmove') {
2301
- targetTouch = [...e.changedTouches].find(t => t.identifier === data.touchId);
2302
- if (!targetTouch || targetTouch.identifier !== data.touchId) return;
2303
- } else {
2304
- targetTouch = e;
2305
- }
2306
- if (!data.isTouched) {
2307
- if (data.startMoving && data.isScrolling) {
2308
- swiper.emit('touchMoveOpposite', e);
2309
- }
2310
- return;
2311
- }
2312
- const pageX = targetTouch.pageX;
2313
- const pageY = targetTouch.pageY;
2314
- if (e.preventedByNestedSwiper) {
2315
- touches.startX = pageX;
2316
- touches.startY = pageY;
2317
- return;
2318
- }
2319
- if (!swiper.allowTouchMove) {
2320
- if (!e.target.matches(data.focusableElements)) {
2321
- swiper.allowClick = false;
2322
- }
2323
- if (data.isTouched) {
2324
- Object.assign(touches, {
2325
- startX: pageX,
2326
- startY: pageY,
2327
- currentX: pageX,
2328
- currentY: pageY
2329
- });
2330
- data.touchStartTime = utils.h();
2331
- }
2332
- return;
2333
- }
2334
- if (params.touchReleaseOnEdges && !params.loop) {
2335
- if (swiper.isVertical()) {
2336
- // Vertical
2337
- if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
2338
- data.isTouched = false;
2339
- data.isMoved = false;
2340
- return;
2341
- }
2342
- } else if (rtl && (pageX > touches.startX && -swiper.translate <= swiper.maxTranslate() || pageX < touches.startX && -swiper.translate >= swiper.minTranslate())) {
2343
- return;
2344
- } else if (!rtl && (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate())) {
2345
- return;
2346
- }
2347
- }
2348
- if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== e.target && e.pointerType !== 'mouse') {
2349
- document.activeElement.blur();
2350
- }
2351
- if (document.activeElement) {
2352
- if (e.target === document.activeElement && e.target.matches(data.focusableElements)) {
2353
- data.isMoved = true;
2354
- swiper.allowClick = false;
2355
- return;
2356
- }
2357
- }
2358
- if (data.allowTouchCallbacks) {
2359
- swiper.emit('touchMove', e);
2360
- }
2361
- touches.previousX = touches.currentX;
2362
- touches.previousY = touches.currentY;
2363
- touches.currentX = pageX;
2364
- touches.currentY = pageY;
2365
- const diffX = touches.currentX - touches.startX;
2366
- const diffY = touches.currentY - touches.startY;
2367
- if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
2368
- if (typeof data.isScrolling === 'undefined') {
2369
- let touchAngle;
2370
- if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
2371
- data.isScrolling = false;
2372
- } else {
2373
- // eslint-disable-next-line
2374
- if (diffX * diffX + diffY * diffY >= 25) {
2375
- touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
2376
- data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
2377
- }
2378
- }
2379
- }
2380
- if (data.isScrolling) {
2381
- swiper.emit('touchMoveOpposite', e);
2382
- }
2383
- if (typeof data.startMoving === 'undefined') {
2384
- if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
2385
- data.startMoving = true;
2386
- }
2387
- }
2388
- if (data.isScrolling || e.type === 'touchmove' && data.preventTouchMoveFromPointerMove) {
2389
- data.isTouched = false;
2390
- return;
2391
- }
2392
- if (!data.startMoving) {
2393
- return;
2394
- }
2395
- swiper.allowClick = false;
2396
- if (!params.cssMode && e.cancelable) {
2397
- e.preventDefault();
2398
- }
2399
- if (params.touchMoveStopPropagation && !params.nested) {
2400
- e.stopPropagation();
2401
- }
2402
- let diff = swiper.isHorizontal() ? diffX : diffY;
2403
- let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY;
2404
- if (params.oneWayMovement) {
2405
- diff = Math.abs(diff) * (rtl ? 1 : -1);
2406
- touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1);
2407
- }
2408
- touches.diff = diff;
2409
- diff *= params.touchRatio;
2410
- if (rtl) {
2411
- diff = -diff;
2412
- touchesDiff = -touchesDiff;
2413
- }
2414
- const prevTouchesDirection = swiper.touchesDirection;
2415
- swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
2416
- swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next';
2417
- const isLoop = swiper.params.loop && !params.cssMode;
2418
- const allowLoopFix = swiper.touchesDirection === 'next' && swiper.allowSlideNext || swiper.touchesDirection === 'prev' && swiper.allowSlidePrev;
2419
- if (!data.isMoved) {
2420
- if (isLoop && allowLoopFix) {
2421
- swiper.loopFix({
2422
- direction: swiper.swipeDirection
2423
- });
2424
- }
2425
- data.startTranslate = swiper.getTranslate();
2426
- swiper.setTransition(0);
2427
- if (swiper.animating) {
2428
- const evt = new window.CustomEvent('transitionend', {
2429
- bubbles: true,
2430
- cancelable: true,
2431
- detail: {
2432
- bySwiperTouchMove: true
2433
- }
2434
- });
2435
- swiper.wrapperEl.dispatchEvent(evt);
2436
- }
2437
- data.allowMomentumBounce = false;
2438
- // Grab Cursor
2439
- if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
2440
- swiper.setGrabCursor(true);
2441
- }
2442
- swiper.emit('sliderFirstMove', e);
2443
- }
2444
- new Date().getTime();
2445
- if (params._loopSwapReset !== false && data.isMoved && data.allowThresholdMove && prevTouchesDirection !== swiper.touchesDirection && isLoop && allowLoopFix && Math.abs(diff) >= 1) {
2446
- Object.assign(touches, {
2447
- startX: pageX,
2448
- startY: pageY,
2449
- currentX: pageX,
2450
- currentY: pageY,
2451
- startTranslate: data.currentTranslate
2452
- });
2453
- data.loopSwapReset = true;
2454
- data.startTranslate = data.currentTranslate;
2455
- return;
2456
- }
2457
- swiper.emit('sliderMove', e);
2458
- data.isMoved = true;
2459
- data.currentTranslate = diff + data.startTranslate;
2460
- let disableParentSwiper = true;
2461
- let resistanceRatio = params.resistanceRatio;
2462
- if (params.touchReleaseOnEdges) {
2463
- resistanceRatio = 0;
2464
- }
2465
- if (diff > 0) {
2466
- if (isLoop && allowLoopFix && true && data.allowThresholdMove && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.slidesSizesGrid[swiper.activeIndex + 1] - (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.activeIndex + 1] + swiper.params.spaceBetween : 0) - swiper.params.spaceBetween : swiper.minTranslate())) {
2467
- swiper.loopFix({
2468
- direction: 'prev',
2469
- setTranslate: true,
2470
- activeSlideIndex: 0
2471
- });
2472
- }
2473
- if (data.currentTranslate > swiper.minTranslate()) {
2474
- disableParentSwiper = false;
2475
- if (params.resistance) {
2476
- data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
2477
- }
2478
- }
2479
- } else if (diff < 0) {
2480
- if (isLoop && allowLoopFix && true && data.allowThresholdMove && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween + (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween : 0) : swiper.maxTranslate())) {
2481
- swiper.loopFix({
2482
- direction: 'next',
2483
- setTranslate: true,
2484
- activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)))
2485
- });
2486
- }
2487
- if (data.currentTranslate < swiper.maxTranslate()) {
2488
- disableParentSwiper = false;
2489
- if (params.resistance) {
2490
- data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
2491
- }
2492
- }
2493
- }
2494
- if (disableParentSwiper) {
2495
- e.preventedByNestedSwiper = true;
2496
- }
2497
-
2498
- // Directions locks
2499
- if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
2500
- data.currentTranslate = data.startTranslate;
2501
- }
2502
- if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
2503
- data.currentTranslate = data.startTranslate;
2504
- }
2505
- if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
2506
- data.currentTranslate = data.startTranslate;
2507
- }
2508
-
2509
- // Threshold
2510
- if (params.threshold > 0) {
2511
- if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
2512
- if (!data.allowThresholdMove) {
2513
- data.allowThresholdMove = true;
2514
- touches.startX = touches.currentX;
2515
- touches.startY = touches.currentY;
2516
- data.currentTranslate = data.startTranslate;
2517
- touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
2518
- return;
2519
- }
2520
- } else {
2521
- data.currentTranslate = data.startTranslate;
2522
- return;
2523
- }
2524
- }
2525
- if (!params.followFinger || params.cssMode) return;
2526
-
2527
- // Update active index in free mode
2528
- if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
2529
- swiper.updateActiveIndex();
2530
- swiper.updateSlidesClasses();
2531
- }
2532
- if (params.freeMode && params.freeMode.enabled && swiper.freeMode) {
2533
- swiper.freeMode.onTouchMove();
2534
- }
2535
- // Update progress
2536
- swiper.updateProgress(data.currentTranslate);
2537
- // Update translate
2538
- swiper.setTranslate(data.currentTranslate);
2539
- }
2540
-
2541
- function onTouchEnd(event) {
2542
- const swiper = this;
2543
- const data = swiper.touchEventsData;
2544
- let e = event;
2545
- if (e.originalEvent) e = e.originalEvent;
2546
- let targetTouch;
2547
- const isTouchEvent = e.type === 'touchend' || e.type === 'touchcancel';
2548
- if (!isTouchEvent) {
2549
- if (data.touchId !== null) return; // return from pointer if we use touch
2550
- if (e.pointerId !== data.pointerId) return;
2551
- targetTouch = e;
2552
- } else {
2553
- targetTouch = [...e.changedTouches].find(t => t.identifier === data.touchId);
2554
- if (!targetTouch || targetTouch.identifier !== data.touchId) return;
2555
- }
2556
- if (['pointercancel', 'pointerout', 'pointerleave', 'contextmenu'].includes(e.type)) {
2557
- const proceed = ['pointercancel', 'contextmenu'].includes(e.type) && (swiper.browser.isSafari || swiper.browser.isWebView);
2558
- if (!proceed) {
2559
- return;
2560
- }
2561
- }
2562
- data.pointerId = null;
2563
- data.touchId = null;
2564
- const {
2565
- params,
2566
- touches,
2567
- rtlTranslate: rtl,
2568
- slidesGrid,
2569
- enabled
2570
- } = swiper;
2571
- if (!enabled) return;
2572
- if (!params.simulateTouch && e.pointerType === 'mouse') return;
2573
- if (data.allowTouchCallbacks) {
2574
- swiper.emit('touchEnd', e);
2575
- }
2576
- data.allowTouchCallbacks = false;
2577
- if (!data.isTouched) {
2578
- if (data.isMoved && params.grabCursor) {
2579
- swiper.setGrabCursor(false);
2580
- }
2581
- data.isMoved = false;
2582
- data.startMoving = false;
2583
- return;
2584
- }
2585
-
2586
- // Return Grab Cursor
2587
- if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
2588
- swiper.setGrabCursor(false);
2589
- }
2590
-
2591
- // Time diff
2592
- const touchEndTime = utils.h();
2593
- const timeDiff = touchEndTime - data.touchStartTime;
2594
-
2595
- // Tap, doubleTap, Click
2596
- if (swiper.allowClick) {
2597
- const pathTree = e.path || e.composedPath && e.composedPath();
2598
- swiper.updateClickedSlide(pathTree && pathTree[0] || e.target, pathTree);
2599
- swiper.emit('tap click', e);
2600
- if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
2601
- swiper.emit('doubleTap doubleClick', e);
2602
- }
2603
- }
2604
- data.lastClickTime = utils.h();
2605
- utils.n(() => {
2606
- if (!swiper.destroyed) swiper.allowClick = true;
2607
- });
2608
- if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 && !data.loopSwapReset || data.currentTranslate === data.startTranslate && !data.loopSwapReset) {
2609
- data.isTouched = false;
2610
- data.isMoved = false;
2611
- data.startMoving = false;
2612
- return;
2613
- }
2614
- data.isTouched = false;
2615
- data.isMoved = false;
2616
- data.startMoving = false;
2617
- let currentPos;
2618
- if (params.followFinger) {
2619
- currentPos = rtl ? swiper.translate : -swiper.translate;
2620
- } else {
2621
- currentPos = -data.currentTranslate;
2622
- }
2623
- if (params.cssMode) {
2624
- return;
2625
- }
2626
- if (params.freeMode && params.freeMode.enabled) {
2627
- swiper.freeMode.onTouchEnd({
2628
- currentPos
2629
- });
2630
- return;
2631
- }
2632
-
2633
- // Find current slide
2634
- const swipeToLast = currentPos >= -swiper.maxTranslate() && !swiper.params.loop;
2635
- let stopIndex = 0;
2636
- let groupSize = swiper.slidesSizesGrid[0];
2637
- for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
2638
- const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
2639
- if (typeof slidesGrid[i + increment] !== 'undefined') {
2640
- if (swipeToLast || currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
2641
- stopIndex = i;
2642
- groupSize = slidesGrid[i + increment] - slidesGrid[i];
2643
- }
2644
- } else if (swipeToLast || currentPos >= slidesGrid[i]) {
2645
- stopIndex = i;
2646
- groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
2647
- }
2648
- }
2649
- let rewindFirstIndex = null;
2650
- let rewindLastIndex = null;
2651
- if (params.rewind) {
2652
- if (swiper.isBeginning) {
2653
- rewindLastIndex = params.virtual && params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
2654
- } else if (swiper.isEnd) {
2655
- rewindFirstIndex = 0;
2656
- }
2657
- }
2658
- // Find current slide size
2659
- const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
2660
- const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
2661
- if (timeDiff > params.longSwipesMs) {
2662
- // Long touches
2663
- if (!params.longSwipes) {
2664
- swiper.slideTo(swiper.activeIndex);
2665
- return;
2666
- }
2667
- if (swiper.swipeDirection === 'next') {
2668
- if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
2669
- }
2670
- if (swiper.swipeDirection === 'prev') {
2671
- if (ratio > 1 - params.longSwipesRatio) {
2672
- swiper.slideTo(stopIndex + increment);
2673
- } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
2674
- swiper.slideTo(rewindLastIndex);
2675
- } else {
2676
- swiper.slideTo(stopIndex);
2677
- }
2678
- }
2679
- } else {
2680
- // Short swipes
2681
- if (!params.shortSwipes) {
2682
- swiper.slideTo(swiper.activeIndex);
2683
- return;
2684
- }
2685
- const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
2686
- if (!isNavButtonTarget) {
2687
- if (swiper.swipeDirection === 'next') {
2688
- swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
2689
- }
2690
- if (swiper.swipeDirection === 'prev') {
2691
- swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
2692
- }
2693
- } else if (e.target === swiper.navigation.nextEl) {
2694
- swiper.slideTo(stopIndex + increment);
2695
- } else {
2696
- swiper.slideTo(stopIndex);
2697
- }
2698
- }
2699
- }
2700
-
2701
- function onResize() {
2702
- const swiper = this;
2703
- const {
2704
- params,
2705
- el
2706
- } = swiper;
2707
- if (el && el.offsetWidth === 0) return;
2708
-
2709
- // Breakpoints
2710
- if (params.breakpoints) {
2711
- swiper.setBreakpoint();
2712
- }
2713
-
2714
- // Save locks
2715
- const {
2716
- allowSlideNext,
2717
- allowSlidePrev,
2718
- snapGrid
2719
- } = swiper;
2720
- const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
2721
-
2722
- // Disable locks on resize
2723
- swiper.allowSlideNext = true;
2724
- swiper.allowSlidePrev = true;
2725
- swiper.updateSize();
2726
- swiper.updateSlides();
2727
- swiper.updateSlidesClasses();
2728
- const isVirtualLoop = isVirtual && params.loop;
2729
- if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) {
2730
- swiper.slideTo(swiper.slides.length - 1, 0, false, true);
2731
- } else {
2732
- if (swiper.params.loop && !isVirtual) {
2733
- swiper.slideToLoop(swiper.realIndex, 0, false, true);
2734
- } else {
2735
- swiper.slideTo(swiper.activeIndex, 0, false, true);
2736
- }
2737
- }
2738
- if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
2739
- clearTimeout(swiper.autoplay.resizeTimeout);
2740
- swiper.autoplay.resizeTimeout = setTimeout(() => {
2741
- if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
2742
- swiper.autoplay.resume();
2743
- }
2744
- }, 500);
2745
- }
2746
- // Return locks after resize
2747
- swiper.allowSlidePrev = allowSlidePrev;
2748
- swiper.allowSlideNext = allowSlideNext;
2749
- if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
2750
- swiper.checkOverflow();
2751
- }
2752
- }
2753
-
2754
- function onClick(e) {
2755
- const swiper = this;
2756
- if (!swiper.enabled) return;
2757
- if (!swiper.allowClick) {
2758
- if (swiper.params.preventClicks) e.preventDefault();
2759
- if (swiper.params.preventClicksPropagation && swiper.animating) {
2760
- e.stopPropagation();
2761
- e.stopImmediatePropagation();
2762
- }
2763
- }
2764
- }
2765
-
2766
- function onScroll() {
2767
- const swiper = this;
2768
- const {
2769
- wrapperEl,
2770
- rtlTranslate,
2771
- enabled
2772
- } = swiper;
2773
- if (!enabled) return;
2774
- swiper.previousTranslate = swiper.translate;
2775
- if (swiper.isHorizontal()) {
2776
- swiper.translate = -wrapperEl.scrollLeft;
2777
- } else {
2778
- swiper.translate = -wrapperEl.scrollTop;
2779
- }
2780
- // eslint-disable-next-line
2781
- if (swiper.translate === 0) swiper.translate = 0;
2782
- swiper.updateActiveIndex();
2783
- swiper.updateSlidesClasses();
2784
- let newProgress;
2785
- const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
2786
- if (translatesDiff === 0) {
2787
- newProgress = 0;
2788
- } else {
2789
- newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
2790
- }
2791
- if (newProgress !== swiper.progress) {
2792
- swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
2793
- }
2794
- swiper.emit('setTranslate', swiper.translate, false);
2795
- }
2796
-
2797
- function onLoad(e) {
2798
- const swiper = this;
2799
- processLazyPreloader(swiper, e.target);
2800
- if (swiper.params.cssMode || swiper.params.slidesPerView !== 'auto' && !swiper.params.autoHeight) {
2801
- return;
2802
- }
2803
- swiper.update();
2804
- }
2805
-
2806
- function onDocumentTouchStart() {
2807
- const swiper = this;
2808
- if (swiper.documentTouchHandlerProceeded) return;
2809
- swiper.documentTouchHandlerProceeded = true;
2810
- if (swiper.params.touchReleaseOnEdges) {
2811
- swiper.el.style.touchAction = 'auto';
2812
- }
2813
- }
2814
-
2815
- const events = (swiper, method) => {
2816
- const document = ssrWindow_esm.g();
2817
- const {
2818
- params,
2819
- el,
2820
- wrapperEl,
2821
- device
2822
- } = swiper;
2823
- const capture = !!params.nested;
2824
- const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
2825
- const swiperMethod = method;
2826
- if (!el || typeof el === 'string') return;
2827
-
2828
- // Touch Events
2829
- document[domMethod]('touchstart', swiper.onDocumentTouchStart, {
2830
- passive: false,
2831
- capture
2832
- });
2833
- el[domMethod]('touchstart', swiper.onTouchStart, {
2834
- passive: false
2835
- });
2836
- el[domMethod]('pointerdown', swiper.onTouchStart, {
2837
- passive: false
2838
- });
2839
- document[domMethod]('touchmove', swiper.onTouchMove, {
2840
- passive: false,
2841
- capture
2842
- });
2843
- document[domMethod]('pointermove', swiper.onTouchMove, {
2844
- passive: false,
2845
- capture
2846
- });
2847
- document[domMethod]('touchend', swiper.onTouchEnd, {
2848
- passive: true
2849
- });
2850
- document[domMethod]('pointerup', swiper.onTouchEnd, {
2851
- passive: true
2852
- });
2853
- document[domMethod]('pointercancel', swiper.onTouchEnd, {
2854
- passive: true
2855
- });
2856
- document[domMethod]('touchcancel', swiper.onTouchEnd, {
2857
- passive: true
2858
- });
2859
- document[domMethod]('pointerout', swiper.onTouchEnd, {
2860
- passive: true
2861
- });
2862
- document[domMethod]('pointerleave', swiper.onTouchEnd, {
2863
- passive: true
2864
- });
2865
- document[domMethod]('contextmenu', swiper.onTouchEnd, {
2866
- passive: true
2867
- });
2868
-
2869
- // Prevent Links Clicks
2870
- if (params.preventClicks || params.preventClicksPropagation) {
2871
- el[domMethod]('click', swiper.onClick, true);
2872
- }
2873
- if (params.cssMode) {
2874
- wrapperEl[domMethod]('scroll', swiper.onScroll);
2875
- }
2876
-
2877
- // Resize handler
2878
- if (params.updateOnWindowResize) {
2879
- swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true);
2880
- } else {
2881
- swiper[swiperMethod]('observerUpdate', onResize, true);
2882
- }
2883
-
2884
- // Images loader
2885
- el[domMethod]('load', swiper.onLoad, {
2886
- capture: true
2887
- });
2888
- };
2889
- function attachEvents() {
2890
- const swiper = this;
2891
- const {
2892
- params
2893
- } = swiper;
2894
- swiper.onTouchStart = onTouchStart.bind(swiper);
2895
- swiper.onTouchMove = onTouchMove.bind(swiper);
2896
- swiper.onTouchEnd = onTouchEnd.bind(swiper);
2897
- swiper.onDocumentTouchStart = onDocumentTouchStart.bind(swiper);
2898
- if (params.cssMode) {
2899
- swiper.onScroll = onScroll.bind(swiper);
2900
- }
2901
- swiper.onClick = onClick.bind(swiper);
2902
- swiper.onLoad = onLoad.bind(swiper);
2903
- events(swiper, 'on');
2904
- }
2905
- function detachEvents() {
2906
- const swiper = this;
2907
- events(swiper, 'off');
2908
- }
2909
- var events$1 = {
2910
- attachEvents,
2911
- detachEvents
2912
- };
2913
-
2914
- const isGridEnabled = (swiper, params) => {
2915
- return swiper.grid && params.grid && params.grid.rows > 1;
2916
- };
2917
- function setBreakpoint() {
2918
- const swiper = this;
2919
- const {
2920
- realIndex,
2921
- initialized,
2922
- params,
2923
- el
2924
- } = swiper;
2925
- const breakpoints = params.breakpoints;
2926
- if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
2927
- const document = ssrWindow_esm.g();
2928
-
2929
- // Get breakpoint for window/container width and update parameters
2930
- const breakpointsBase = params.breakpointsBase === 'window' || !params.breakpointsBase ? params.breakpointsBase : 'container';
2931
- const breakpointContainer = ['window', 'container'].includes(params.breakpointsBase) || !params.breakpointsBase ? swiper.el : document.querySelector(params.breakpointsBase);
2932
- const breakpoint = swiper.getBreakpoint(breakpoints, breakpointsBase, breakpointContainer);
2933
- if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
2934
- const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
2935
- const breakpointParams = breakpointOnlyParams || swiper.originalParams;
2936
- const wasMultiRow = isGridEnabled(swiper, params);
2937
- const isMultiRow = isGridEnabled(swiper, breakpointParams);
2938
- const wasGrabCursor = swiper.params.grabCursor;
2939
- const isGrabCursor = breakpointParams.grabCursor;
2940
- const wasEnabled = params.enabled;
2941
- if (wasMultiRow && !isMultiRow) {
2942
- el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`);
2943
- swiper.emitContainerClasses();
2944
- } else if (!wasMultiRow && isMultiRow) {
2945
- el.classList.add(`${params.containerModifierClass}grid`);
2946
- if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
2947
- el.classList.add(`${params.containerModifierClass}grid-column`);
2948
- }
2949
- swiper.emitContainerClasses();
2950
- }
2951
- if (wasGrabCursor && !isGrabCursor) {
2952
- swiper.unsetGrabCursor();
2953
- } else if (!wasGrabCursor && isGrabCursor) {
2954
- swiper.setGrabCursor();
2955
- }
2956
-
2957
- // Toggle navigation, pagination, scrollbar
2958
- ['navigation', 'pagination', 'scrollbar'].forEach(prop => {
2959
- if (typeof breakpointParams[prop] === 'undefined') return;
2960
- const wasModuleEnabled = params[prop] && params[prop].enabled;
2961
- const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled;
2962
- if (wasModuleEnabled && !isModuleEnabled) {
2963
- swiper[prop].disable();
2964
- }
2965
- if (!wasModuleEnabled && isModuleEnabled) {
2966
- swiper[prop].enable();
2967
- }
2968
- });
2969
- const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
2970
- const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
2971
- const wasLoop = params.loop;
2972
- if (directionChanged && initialized) {
2973
- swiper.changeDirection();
2974
- }
2975
- utils.x(swiper.params, breakpointParams);
2976
- const isEnabled = swiper.params.enabled;
2977
- const hasLoop = swiper.params.loop;
2978
- Object.assign(swiper, {
2979
- allowTouchMove: swiper.params.allowTouchMove,
2980
- allowSlideNext: swiper.params.allowSlideNext,
2981
- allowSlidePrev: swiper.params.allowSlidePrev
2982
- });
2983
- if (wasEnabled && !isEnabled) {
2984
- swiper.disable();
2985
- } else if (!wasEnabled && isEnabled) {
2986
- swiper.enable();
2987
- }
2988
- swiper.currentBreakpoint = breakpoint;
2989
- swiper.emit('_beforeBreakpoint', breakpointParams);
2990
- if (initialized) {
2991
- if (needsReLoop) {
2992
- swiper.loopDestroy();
2993
- swiper.loopCreate(realIndex);
2994
- swiper.updateSlides();
2995
- } else if (!wasLoop && hasLoop) {
2996
- swiper.loopCreate(realIndex);
2997
- swiper.updateSlides();
2998
- } else if (wasLoop && !hasLoop) {
2999
- swiper.loopDestroy();
3000
- }
3001
- }
3002
- swiper.emit('breakpoint', breakpointParams);
3003
- }
3004
-
3005
- function getBreakpoint(breakpoints, base = 'window', containerEl) {
3006
- if (!breakpoints || base === 'container' && !containerEl) return undefined;
3007
- let breakpoint = false;
3008
- const window = ssrWindow_esm.a();
3009
- const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight;
3010
- const points = Object.keys(breakpoints).map(point => {
3011
- if (typeof point === 'string' && point.indexOf('@') === 0) {
3012
- const minRatio = parseFloat(point.substr(1));
3013
- const value = currentHeight * minRatio;
3014
- return {
3015
- value,
3016
- point
3017
- };
3018
- }
3019
- return {
3020
- value: point,
3021
- point
3022
- };
3023
- });
3024
- points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
3025
- for (let i = 0; i < points.length; i += 1) {
3026
- const {
3027
- point,
3028
- value
3029
- } = points[i];
3030
- if (base === 'window') {
3031
- if (window.matchMedia(`(min-width: ${value}px)`).matches) {
3032
- breakpoint = point;
3033
- }
3034
- } else if (value <= containerEl.clientWidth) {
3035
- breakpoint = point;
3036
- }
3037
- }
3038
- return breakpoint || 'max';
3039
- }
3040
-
3041
- var breakpoints = {
3042
- setBreakpoint,
3043
- getBreakpoint
3044
- };
3045
-
3046
- function prepareClasses(entries, prefix) {
3047
- const resultClasses = [];
3048
- entries.forEach(item => {
3049
- if (typeof item === 'object') {
3050
- Object.keys(item).forEach(classNames => {
3051
- if (item[classNames]) {
3052
- resultClasses.push(prefix + classNames);
3053
- }
3054
- });
3055
- } else if (typeof item === 'string') {
3056
- resultClasses.push(prefix + item);
3057
- }
3058
- });
3059
- return resultClasses;
3060
- }
3061
- function addClasses() {
3062
- const swiper = this;
3063
- const {
3064
- classNames,
3065
- params,
3066
- rtl,
3067
- el,
3068
- device
3069
- } = swiper;
3070
- // prettier-ignore
3071
- const suffixes = prepareClasses(['initialized', params.direction, {
3072
- 'free-mode': swiper.params.freeMode && params.freeMode.enabled
3073
- }, {
3074
- 'autoheight': params.autoHeight
3075
- }, {
3076
- 'rtl': rtl
3077
- }, {
3078
- 'grid': params.grid && params.grid.rows > 1
3079
- }, {
3080
- 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
3081
- }, {
3082
- 'android': device.android
3083
- }, {
3084
- 'ios': device.ios
3085
- }, {
3086
- 'css-mode': params.cssMode
3087
- }, {
3088
- 'centered': params.cssMode && params.centeredSlides
3089
- }, {
3090
- 'watch-progress': params.watchSlidesProgress
3091
- }], params.containerModifierClass);
3092
- classNames.push(...suffixes);
3093
- el.classList.add(...classNames);
3094
- swiper.emitContainerClasses();
3095
- }
3096
-
3097
- function removeClasses() {
3098
- const swiper = this;
3099
- const {
3100
- el,
3101
- classNames
3102
- } = swiper;
3103
- if (!el || typeof el === 'string') return;
3104
- el.classList.remove(...classNames);
3105
- swiper.emitContainerClasses();
3106
- }
3107
-
3108
- var classes = {
3109
- addClasses,
3110
- removeClasses
3111
- };
3112
-
3113
- function checkOverflow() {
3114
- const swiper = this;
3115
- const {
3116
- isLocked: wasLocked,
3117
- params
3118
- } = swiper;
3119
- const {
3120
- slidesOffsetBefore
3121
- } = params;
3122
- if (slidesOffsetBefore) {
3123
- const lastSlideIndex = swiper.slides.length - 1;
3124
- const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
3125
- swiper.isLocked = swiper.size > lastSlideRightEdge;
3126
- } else {
3127
- swiper.isLocked = swiper.snapGrid.length === 1;
3128
- }
3129
- if (params.allowSlideNext === true) {
3130
- swiper.allowSlideNext = !swiper.isLocked;
3131
- }
3132
- if (params.allowSlidePrev === true) {
3133
- swiper.allowSlidePrev = !swiper.isLocked;
3134
- }
3135
- if (wasLocked && wasLocked !== swiper.isLocked) {
3136
- swiper.isEnd = false;
3137
- }
3138
- if (wasLocked !== swiper.isLocked) {
3139
- swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
3140
- }
3141
- }
3142
- var checkOverflow$1 = {
3143
- checkOverflow
3144
- };
3145
-
3146
- var defaults = {
3147
- init: true,
3148
- direction: 'horizontal',
3149
- oneWayMovement: false,
3150
- swiperElementNodeName: 'SWIPER-CONTAINER',
3151
- touchEventsTarget: 'wrapper',
3152
- initialSlide: 0,
3153
- speed: 300,
3154
- cssMode: false,
3155
- updateOnWindowResize: true,
3156
- resizeObserver: true,
3157
- nested: false,
3158
- createElements: false,
3159
- eventsPrefix: 'swiper',
3160
- enabled: true,
3161
- focusableElements: 'input, select, option, textarea, button, video, label',
3162
- // Overrides
3163
- width: null,
3164
- height: null,
3165
- //
3166
- preventInteractionOnTransition: false,
3167
- // ssr
3168
- userAgent: null,
3169
- url: null,
3170
- // To support iOS's swipe-to-go-back gesture (when being used in-app).
3171
- edgeSwipeDetection: false,
3172
- edgeSwipeThreshold: 20,
3173
- // Autoheight
3174
- autoHeight: false,
3175
- // Set wrapper width
3176
- setWrapperSize: false,
3177
- // Virtual Translate
3178
- virtualTranslate: false,
3179
- // Effects
3180
- effect: 'slide',
3181
- // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
3182
-
3183
- // Breakpoints
3184
- breakpoints: undefined,
3185
- breakpointsBase: 'window',
3186
- // Slides grid
3187
- spaceBetween: 0,
3188
- slidesPerView: 1,
3189
- slidesPerGroup: 1,
3190
- slidesPerGroupSkip: 0,
3191
- slidesPerGroupAuto: false,
3192
- centeredSlides: false,
3193
- centeredSlidesBounds: false,
3194
- slidesOffsetBefore: 0,
3195
- // in px
3196
- slidesOffsetAfter: 0,
3197
- // in px
3198
- normalizeSlideIndex: true,
3199
- centerInsufficientSlides: false,
3200
- snapToSlideEdge: false,
3201
- // Disable swiper and hide navigation when container not overflow
3202
- watchOverflow: true,
3203
- // Round length
3204
- roundLengths: false,
3205
- // Touches
3206
- touchRatio: 1,
3207
- touchAngle: 45,
3208
- simulateTouch: true,
3209
- shortSwipes: true,
3210
- longSwipes: true,
3211
- longSwipesRatio: 0.5,
3212
- longSwipesMs: 300,
3213
- followFinger: true,
3214
- allowTouchMove: true,
3215
- threshold: 5,
3216
- touchMoveStopPropagation: false,
3217
- touchStartPreventDefault: true,
3218
- touchStartForcePreventDefault: false,
3219
- touchReleaseOnEdges: false,
3220
- // Unique Navigation Elements
3221
- uniqueNavElements: true,
3222
- // Resistance
3223
- resistance: true,
3224
- resistanceRatio: 0.85,
3225
- // Progress
3226
- watchSlidesProgress: false,
3227
- // Cursor
3228
- grabCursor: false,
3229
- // Clicks
3230
- preventClicks: true,
3231
- preventClicksPropagation: true,
3232
- slideToClickedSlide: false,
3233
- // loop
3234
- loop: false,
3235
- loopAddBlankSlides: true,
3236
- loopAdditionalSlides: 0,
3237
- loopPreventsSliding: true,
3238
- // rewind
3239
- rewind: false,
3240
- // Swiping/no swiping
3241
- allowSlidePrev: true,
3242
- allowSlideNext: true,
3243
- swipeHandler: null,
3244
- // '.swipe-handler',
3245
- noSwiping: true,
3246
- noSwipingClass: 'swiper-no-swiping',
3247
- noSwipingSelector: null,
3248
- // Passive Listeners
3249
- passiveListeners: true,
3250
- maxBackfaceHiddenSlides: 10,
3251
- // NS
3252
- containerModifierClass: 'swiper-',
3253
- // NEW
3254
- slideClass: 'swiper-slide',
3255
- slideBlankClass: 'swiper-slide-blank',
3256
- slideActiveClass: 'swiper-slide-active',
3257
- slideVisibleClass: 'swiper-slide-visible',
3258
- slideFullyVisibleClass: 'swiper-slide-fully-visible',
3259
- slideNextClass: 'swiper-slide-next',
3260
- slidePrevClass: 'swiper-slide-prev',
3261
- wrapperClass: 'swiper-wrapper',
3262
- lazyPreloaderClass: 'swiper-lazy-preloader',
3263
- lazyPreloadPrevNext: 0,
3264
- // Callbacks
3265
- runCallbacksOnInit: true,
3266
- // Internals
3267
- _emitClasses: false
3268
- };
3269
-
3270
- function moduleExtendParams(params, allModulesParams) {
3271
- return function extendParams(obj = {}) {
3272
- const moduleParamName = Object.keys(obj)[0];
3273
- const moduleParams = obj[moduleParamName];
3274
- if (typeof moduleParams !== 'object' || moduleParams === null) {
3275
- utils.x(allModulesParams, obj);
3276
- return;
3277
- }
3278
- if (params[moduleParamName] === true) {
3279
- params[moduleParamName] = {
3280
- enabled: true
3281
- };
3282
- }
3283
- if (moduleParamName === 'navigation' && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].prevEl && !params[moduleParamName].nextEl) {
3284
- params[moduleParamName].auto = true;
3285
- }
3286
- if (['pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].el) {
3287
- params[moduleParamName].auto = true;
3288
- }
3289
- if (!(moduleParamName in params && 'enabled' in moduleParams)) {
3290
- utils.x(allModulesParams, obj);
3291
- return;
3292
- }
3293
- if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) {
3294
- params[moduleParamName].enabled = true;
3295
- }
3296
- if (!params[moduleParamName]) params[moduleParamName] = {
3297
- enabled: false
3298
- };
3299
- utils.x(allModulesParams, obj);
3300
- };
3301
- }
3302
-
3303
- /* eslint no-param-reassign: "off" */
3304
- const prototypes = {
3305
- eventsEmitter,
3306
- update,
3307
- translate,
3308
- transition,
3309
- slide,
3310
- loop,
3311
- grabCursor,
3312
- events: events$1,
3313
- breakpoints,
3314
- checkOverflow: checkOverflow$1,
3315
- classes
3316
- };
3317
- const extendedDefaults = {};
3318
- class Swiper {
3319
- constructor(...args) {
3320
- let el;
3321
- let params;
3322
- if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') {
3323
- params = args[0];
3324
- } else {
3325
- [el, params] = args;
3326
- }
3327
- if (!params) params = {};
3328
- params = utils.x({}, params);
3329
- if (el && !params.el) params.el = el;
3330
- const document = ssrWindow_esm.g();
3331
- if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) {
3332
- const swipers = [];
3333
- document.querySelectorAll(params.el).forEach(containerEl => {
3334
- const newParams = utils.x({}, params, {
3335
- el: containerEl
3336
- });
3337
- swipers.push(new Swiper(newParams));
3338
- });
3339
- // eslint-disable-next-line no-constructor-return
3340
- return swipers;
3341
- }
3342
-
3343
- // Swiper Instance
3344
- const swiper = this;
3345
- swiper.__swiper__ = true;
3346
- swiper.support = getSupport();
3347
- swiper.device = getDevice({
3348
- userAgent: params.userAgent
3349
- });
3350
- swiper.browser = getBrowser();
3351
- swiper.eventsListeners = {};
3352
- swiper.eventsAnyListeners = [];
3353
- swiper.modules = [...swiper.__modules__];
3354
- if (params.modules && Array.isArray(params.modules)) {
3355
- params.modules.forEach(mod => {
3356
- if (typeof mod === 'function' && swiper.modules.indexOf(mod) < 0) {
3357
- swiper.modules.push(mod);
3358
- }
3359
- });
3360
- }
3361
- const allModulesParams = {};
3362
- swiper.modules.forEach(mod => {
3363
- mod({
3364
- params,
3365
- swiper,
3366
- extendParams: moduleExtendParams(params, allModulesParams),
3367
- on: swiper.on.bind(swiper),
3368
- once: swiper.once.bind(swiper),
3369
- off: swiper.off.bind(swiper),
3370
- emit: swiper.emit.bind(swiper)
3371
- });
3372
- });
3373
-
3374
- // Extend defaults with modules params
3375
- const swiperParams = utils.x({}, defaults, allModulesParams);
3376
-
3377
- // Extend defaults with passed params
3378
- swiper.params = utils.x({}, swiperParams, extendedDefaults, params);
3379
- swiper.originalParams = utils.x({}, swiper.params);
3380
- swiper.passedParams = utils.x({}, params);
3381
-
3382
- // add event listeners
3383
- if (swiper.params && swiper.params.on) {
3384
- Object.keys(swiper.params.on).forEach(eventName => {
3385
- swiper.on(eventName, swiper.params.on[eventName]);
3386
- });
3387
- }
3388
- if (swiper.params && swiper.params.onAny) {
3389
- swiper.onAny(swiper.params.onAny);
3390
- }
3391
-
3392
- // Extend Swiper
3393
- Object.assign(swiper, {
3394
- enabled: swiper.params.enabled,
3395
- el,
3396
- // Classes
3397
- classNames: [],
3398
- // Slides
3399
- slides: [],
3400
- slidesGrid: [],
3401
- snapGrid: [],
3402
- slidesSizesGrid: [],
3403
- // isDirection
3404
- isHorizontal() {
3405
- return swiper.params.direction === 'horizontal';
3406
- },
3407
- isVertical() {
3408
- return swiper.params.direction === 'vertical';
3409
- },
3410
- // Indexes
3411
- activeIndex: 0,
3412
- realIndex: 0,
3413
- //
3414
- isBeginning: true,
3415
- isEnd: false,
3416
- // Props
3417
- translate: 0,
3418
- previousTranslate: 0,
3419
- progress: 0,
3420
- velocity: 0,
3421
- animating: false,
3422
- cssOverflowAdjustment() {
3423
- // Returns 0 unless `translate` is > 2**23
3424
- // Should be subtracted from css values to prevent overflow
3425
- return Math.trunc(this.translate / 2 ** 23) * 2 ** 23;
3426
- },
3427
- // Locks
3428
- allowSlideNext: swiper.params.allowSlideNext,
3429
- allowSlidePrev: swiper.params.allowSlidePrev,
3430
- // Touch Events
3431
- touchEventsData: {
3432
- isTouched: undefined,
3433
- isMoved: undefined,
3434
- allowTouchCallbacks: undefined,
3435
- touchStartTime: undefined,
3436
- isScrolling: undefined,
3437
- currentTranslate: undefined,
3438
- startTranslate: undefined,
3439
- allowThresholdMove: undefined,
3440
- // Form elements to match
3441
- focusableElements: swiper.params.focusableElements,
3442
- // Last click time
3443
- lastClickTime: 0,
3444
- clickTimeout: undefined,
3445
- // Velocities
3446
- velocities: [],
3447
- allowMomentumBounce: undefined,
3448
- startMoving: undefined,
3449
- pointerId: null,
3450
- touchId: null
3451
- },
3452
- // Clicks
3453
- allowClick: true,
3454
- // Touches
3455
- allowTouchMove: swiper.params.allowTouchMove,
3456
- touches: {
3457
- startX: 0,
3458
- startY: 0,
3459
- currentX: 0,
3460
- currentY: 0,
3461
- diff: 0
3462
- },
3463
- // Images
3464
- imagesToLoad: [],
3465
- imagesLoaded: 0
3466
- });
3467
- swiper.emit('_swiper');
3468
-
3469
- // Init
3470
- if (swiper.params.init) {
3471
- swiper.init();
3472
- }
3473
-
3474
- // Return app instance
3475
- // eslint-disable-next-line no-constructor-return
3476
- return swiper;
3477
- }
3478
- getDirectionLabel(property) {
3479
- if (this.isHorizontal()) {
3480
- return property;
3481
- }
3482
- // prettier-ignore
3483
- return {
3484
- 'width': 'height',
3485
- 'margin-top': 'margin-left',
3486
- 'margin-bottom ': 'margin-right',
3487
- 'margin-left': 'margin-top',
3488
- 'margin-right': 'margin-bottom',
3489
- 'padding-left': 'padding-top',
3490
- 'padding-right': 'padding-bottom',
3491
- 'marginRight': 'marginBottom'
3492
- }[property];
3493
- }
3494
- getSlideIndex(slideEl) {
3495
- const {
3496
- slidesEl,
3497
- params
3498
- } = this;
3499
- const slides = utils.e(slidesEl, `.${params.slideClass}, swiper-slide`);
3500
- const firstSlideIndex = utils.j(slides[0]);
3501
- return utils.j(slideEl) - firstSlideIndex;
3502
- }
3503
- getSlideIndexByData(index) {
3504
- return this.getSlideIndex(this.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === index));
3505
- }
3506
- getSlideIndexWhenGrid(index) {
3507
- if (this.grid && this.params.grid && this.params.grid.rows > 1) {
3508
- if (this.params.grid.fill === 'column') {
3509
- index = Math.floor(index / this.params.grid.rows);
3510
- } else if (this.params.grid.fill === 'row') {
3511
- index = index % Math.ceil(this.slides.length / this.params.grid.rows);
3512
- }
3513
- }
3514
- return index;
3515
- }
3516
- recalcSlides() {
3517
- const swiper = this;
3518
- const {
3519
- slidesEl,
3520
- params
3521
- } = swiper;
3522
- swiper.slides = utils.e(slidesEl, `.${params.slideClass}, swiper-slide`);
3523
- }
3524
- enable() {
3525
- const swiper = this;
3526
- if (swiper.enabled) return;
3527
- swiper.enabled = true;
3528
- if (swiper.params.grabCursor) {
3529
- swiper.setGrabCursor();
3530
- }
3531
- swiper.emit('enable');
3532
- }
3533
- disable() {
3534
- const swiper = this;
3535
- if (!swiper.enabled) return;
3536
- swiper.enabled = false;
3537
- if (swiper.params.grabCursor) {
3538
- swiper.unsetGrabCursor();
3539
- }
3540
- swiper.emit('disable');
3541
- }
3542
- setProgress(progress, speed) {
3543
- const swiper = this;
3544
- progress = Math.min(Math.max(progress, 0), 1);
3545
- const min = swiper.minTranslate();
3546
- const max = swiper.maxTranslate();
3547
- const current = (max - min) * progress + min;
3548
- swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed);
3549
- swiper.updateActiveIndex();
3550
- swiper.updateSlidesClasses();
3551
- }
3552
- emitContainerClasses() {
3553
- const swiper = this;
3554
- if (!swiper.params._emitClasses || !swiper.el) return;
3555
- const cls = swiper.el.className.split(' ').filter(className => {
3556
- return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0;
3557
- });
3558
- swiper.emit('_containerClasses', cls.join(' '));
3559
- }
3560
- getSlideClasses(slideEl) {
3561
- const swiper = this;
3562
- if (swiper.destroyed) return '';
3563
- return slideEl.className.split(' ').filter(className => {
3564
- return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0;
3565
- }).join(' ');
3566
- }
3567
- emitSlidesClasses() {
3568
- const swiper = this;
3569
- if (!swiper.params._emitClasses || !swiper.el) return;
3570
- const updates = [];
3571
- swiper.slides.forEach(slideEl => {
3572
- const classNames = swiper.getSlideClasses(slideEl);
3573
- updates.push({
3574
- slideEl,
3575
- classNames
3576
- });
3577
- swiper.emit('_slideClass', slideEl, classNames);
3578
- });
3579
- swiper.emit('_slideClasses', updates);
3580
- }
3581
- slidesPerViewDynamic(view = 'current', exact = false) {
3582
- const swiper = this;
3583
- const {
3584
- params,
3585
- slides,
3586
- slidesGrid,
3587
- slidesSizesGrid,
3588
- size: swiperSize,
3589
- activeIndex
3590
- } = swiper;
3591
- let spv = 1;
3592
- if (typeof params.slidesPerView === 'number') return params.slidesPerView;
3593
- if (params.centeredSlides) {
3594
- let slideSize = slides[activeIndex] ? Math.ceil(slides[activeIndex].swiperSlideSize) : 0;
3595
- let breakLoop;
3596
- for (let i = activeIndex + 1; i < slides.length; i += 1) {
3597
- if (slides[i] && !breakLoop) {
3598
- slideSize += Math.ceil(slides[i].swiperSlideSize);
3599
- spv += 1;
3600
- if (slideSize > swiperSize) breakLoop = true;
3601
- }
3602
- }
3603
- for (let i = activeIndex - 1; i >= 0; i -= 1) {
3604
- if (slides[i] && !breakLoop) {
3605
- slideSize += slides[i].swiperSlideSize;
3606
- spv += 1;
3607
- if (slideSize > swiperSize) breakLoop = true;
3608
- }
3609
- }
3610
- } else {
3611
- // eslint-disable-next-line
3612
- if (view === 'current') {
3613
- for (let i = activeIndex + 1; i < slides.length; i += 1) {
3614
- const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize;
3615
- if (slideInView) {
3616
- spv += 1;
3617
- }
3618
- }
3619
- } else {
3620
- // previous
3621
- for (let i = activeIndex - 1; i >= 0; i -= 1) {
3622
- const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize;
3623
- if (slideInView) {
3624
- spv += 1;
3625
- }
3626
- }
3627
- }
3628
- }
3629
- return spv;
3630
- }
3631
- update() {
3632
- const swiper = this;
3633
- if (!swiper || swiper.destroyed) return;
3634
- const {
3635
- snapGrid,
3636
- params
3637
- } = swiper;
3638
- // Breakpoints
3639
- if (params.breakpoints) {
3640
- swiper.setBreakpoint();
3641
- }
3642
- [...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => {
3643
- if (imageEl.complete) {
3644
- processLazyPreloader(swiper, imageEl);
3645
- }
3646
- });
3647
- swiper.updateSize();
3648
- swiper.updateSlides();
3649
- swiper.updateProgress();
3650
- swiper.updateSlidesClasses();
3651
- function setTranslate() {
3652
- const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
3653
- const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
3654
- swiper.setTranslate(newTranslate);
3655
- swiper.updateActiveIndex();
3656
- swiper.updateSlidesClasses();
3657
- }
3658
- let translated;
3659
- if (params.freeMode && params.freeMode.enabled && !params.cssMode) {
3660
- setTranslate();
3661
- if (params.autoHeight) {
3662
- swiper.updateAutoHeight();
3663
- }
3664
- } else {
3665
- if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !params.centeredSlides) {
3666
- const slides = swiper.virtual && params.virtual.enabled ? swiper.virtual.slides : swiper.slides;
3667
- translated = swiper.slideTo(slides.length - 1, 0, false, true);
3668
- } else {
3669
- translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
3670
- }
3671
- if (!translated) {
3672
- setTranslate();
3673
- }
3674
- }
3675
- if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
3676
- swiper.checkOverflow();
3677
- }
3678
- swiper.emit('update');
3679
- }
3680
- changeDirection(newDirection, needUpdate = true) {
3681
- const swiper = this;
3682
- const currentDirection = swiper.params.direction;
3683
- if (!newDirection) {
3684
- // eslint-disable-next-line
3685
- newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
3686
- }
3687
- if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') {
3688
- return swiper;
3689
- }
3690
- swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`);
3691
- swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`);
3692
- swiper.emitContainerClasses();
3693
- swiper.params.direction = newDirection;
3694
- swiper.slides.forEach(slideEl => {
3695
- if (newDirection === 'vertical') {
3696
- slideEl.style.width = '';
3697
- } else {
3698
- slideEl.style.height = '';
3699
- }
3700
- });
3701
- swiper.emit('changeDirection');
3702
- if (needUpdate) swiper.update();
3703
- return swiper;
3704
- }
3705
- changeLanguageDirection(direction) {
3706
- const swiper = this;
3707
- if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return;
3708
- swiper.rtl = direction === 'rtl';
3709
- swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl;
3710
- if (swiper.rtl) {
3711
- swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`);
3712
- swiper.el.dir = 'rtl';
3713
- } else {
3714
- swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`);
3715
- swiper.el.dir = 'ltr';
3716
- }
3717
- swiper.update();
3718
- }
3719
- mount(element) {
3720
- const swiper = this;
3721
- if (swiper.mounted) return true;
3722
-
3723
- // Find el
3724
- let el = element || swiper.params.el;
3725
- if (typeof el === 'string') {
3726
- el = document.querySelector(el);
3727
- }
3728
- if (!el) {
3729
- return false;
3730
- }
3731
- el.swiper = swiper;
3732
- if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === swiper.params.swiperElementNodeName.toUpperCase()) {
3733
- swiper.isElement = true;
3734
- }
3735
- const getWrapperSelector = () => {
3736
- return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`;
3737
- };
3738
- const getWrapper = () => {
3739
- if (el && el.shadowRoot && el.shadowRoot.querySelector) {
3740
- const res = el.shadowRoot.querySelector(getWrapperSelector());
3741
- // Children needs to return slot items
3742
- return res;
3743
- }
3744
- return utils.e(el, getWrapperSelector())[0];
3745
- };
3746
- // Find Wrapper
3747
- let wrapperEl = getWrapper();
3748
- if (!wrapperEl && swiper.params.createElements) {
3749
- wrapperEl = utils.c('div', swiper.params.wrapperClass);
3750
- el.append(wrapperEl);
3751
- utils.e(el, `.${swiper.params.slideClass}`).forEach(slideEl => {
3752
- wrapperEl.append(slideEl);
3753
- });
3754
- }
3755
- Object.assign(swiper, {
3756
- el,
3757
- wrapperEl,
3758
- slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
3759
- hostEl: swiper.isElement ? el.parentNode.host : el,
3760
- mounted: true,
3761
- // RTL
3762
- rtl: el.dir.toLowerCase() === 'rtl' || utils.q(el, 'direction') === 'rtl',
3763
- rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || utils.q(el, 'direction') === 'rtl'),
3764
- wrongRTL: utils.q(wrapperEl, 'display') === '-webkit-box'
3765
- });
3766
- return true;
3767
- }
3768
- init(el) {
3769
- const swiper = this;
3770
- if (swiper.initialized) return swiper;
3771
- const mounted = swiper.mount(el);
3772
- if (mounted === false) return swiper;
3773
- swiper.emit('beforeInit');
3774
-
3775
- // Set breakpoint
3776
- if (swiper.params.breakpoints) {
3777
- swiper.setBreakpoint();
3778
- }
3779
-
3780
- // Add Classes
3781
- swiper.addClasses();
3782
-
3783
- // Update size
3784
- swiper.updateSize();
3785
-
3786
- // Update slides
3787
- swiper.updateSlides();
3788
- if (swiper.params.watchOverflow) {
3789
- swiper.checkOverflow();
3790
- }
3791
-
3792
- // Set Grab Cursor
3793
- if (swiper.params.grabCursor && swiper.enabled) {
3794
- swiper.setGrabCursor();
3795
- }
3796
-
3797
- // Slide To Initial Slide
3798
- if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
3799
- swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true);
3800
- } else {
3801
- swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true);
3802
- }
3803
-
3804
- // Create loop
3805
- if (swiper.params.loop) {
3806
- swiper.loopCreate(undefined, true);
3807
- }
3808
-
3809
- // Attach events
3810
- swiper.attachEvents();
3811
- const lazyElements = [...swiper.el.querySelectorAll('[loading="lazy"]')];
3812
- if (swiper.isElement) {
3813
- lazyElements.push(...swiper.hostEl.querySelectorAll('[loading="lazy"]'));
3814
- }
3815
- lazyElements.forEach(imageEl => {
3816
- if (imageEl.complete) {
3817
- processLazyPreloader(swiper, imageEl);
3818
- } else {
3819
- imageEl.addEventListener('load', e => {
3820
- processLazyPreloader(swiper, e.target);
3821
- });
3822
- }
3823
- });
3824
- preload(swiper);
3825
-
3826
- // Init Flag
3827
- swiper.initialized = true;
3828
- preload(swiper);
3829
-
3830
- // Emit
3831
- swiper.emit('init');
3832
- swiper.emit('afterInit');
3833
- return swiper;
3834
- }
3835
- destroy(deleteInstance = true, cleanStyles = true) {
3836
- const swiper = this;
3837
- const {
3838
- params,
3839
- el,
3840
- wrapperEl,
3841
- slides
3842
- } = swiper;
3843
- if (typeof swiper.params === 'undefined' || swiper.destroyed) {
3844
- return null;
3845
- }
3846
- swiper.emit('beforeDestroy');
3847
-
3848
- // Init Flag
3849
- swiper.initialized = false;
3850
-
3851
- // Detach events
3852
- swiper.detachEvents();
3853
-
3854
- // Destroy loop
3855
- if (params.loop) {
3856
- swiper.loopDestroy();
3857
- }
3858
-
3859
- // Cleanup styles
3860
- if (cleanStyles) {
3861
- swiper.removeClasses();
3862
- if (el && typeof el !== 'string') {
3863
- el.removeAttribute('style');
3864
- }
3865
- if (wrapperEl) {
3866
- wrapperEl.removeAttribute('style');
3867
- }
3868
- if (slides && slides.length) {
3869
- slides.forEach(slideEl => {
3870
- slideEl.classList.remove(params.slideVisibleClass, params.slideFullyVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass);
3871
- slideEl.removeAttribute('style');
3872
- slideEl.removeAttribute('data-swiper-slide-index');
3873
- });
3874
- }
3875
- }
3876
- swiper.emit('destroy');
3877
-
3878
- // Detach emitter events
3879
- Object.keys(swiper.eventsListeners).forEach(eventName => {
3880
- swiper.off(eventName);
3881
- });
3882
- if (deleteInstance !== false) {
3883
- if (swiper.el && typeof swiper.el !== 'string') {
3884
- swiper.el.swiper = null;
3885
- }
3886
- utils.y(swiper);
3887
- }
3888
- swiper.destroyed = true;
3889
- return null;
3890
- }
3891
- static extendDefaults(newDefaults) {
3892
- utils.x(extendedDefaults, newDefaults);
3893
- }
3894
- static get extendedDefaults() {
3895
- return extendedDefaults;
3896
- }
3897
- static get defaults() {
3898
- return defaults;
3899
- }
3900
- static installModule(mod) {
3901
- if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = [];
3902
- const modules = Swiper.prototype.__modules__;
3903
- if (typeof mod === 'function' && modules.indexOf(mod) < 0) {
3904
- modules.push(mod);
3905
- }
3906
- }
3907
- static use(module) {
3908
- if (Array.isArray(module)) {
3909
- module.forEach(m => Swiper.installModule(m));
3910
- return Swiper;
3911
- }
3912
- Swiper.installModule(module);
3913
- return Swiper;
3914
- }
3915
- }
3916
- Object.keys(prototypes).forEach(prototypeGroup => {
3917
- Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => {
3918
- Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
3919
- });
3920
- });
3921
- Swiper.use([Resize, Observer]);
3922
-
3923
- exports.S = Swiper;
3924
- exports.d = defaults;
3925
- //# sourceMappingURL=swiper-core.js.map