vendor: 14,097 bytes, lines 1-362
1import { a as getWindow } from '../shared/ssr-window.esm.mjs'; 2import { n as nextTick, f as now } from '../shared/utils.mjs'; 3 4/* eslint-disable consistent-return */ 5function Mousewheel(_ref) { 6 let { 7 swiper, 8 extendParams, 9 on, 10 emit 11 } = _ref; 12 const window = getWindow(); 13 extendParams({ 14 mousewheel: { 15 enabled: false, 16 releaseOnEdges: false, 17 invert: false, 18 forceToAxis: false, 19 sensitivity: 1, 20 eventsTarget: 'container', 21 thresholdDelta: null, 22 thresholdTime: null, 23 noMousewheelClass: 'swiper-no-mousewheel' 24 } 25 }); 26 swiper.mousewheel = { 27 enabled: false 28 }; 29 let timeout; 30 let lastScrollTime = now(); 31 let lastEventBeforeSnap; 32 const recentWheelEvents = []; 33 function normalize(e) { 34 // Reasonable defaults 35 const PIXEL_STEP = 10; 36 const LINE_HEIGHT = 40; 37 const PAGE_HEIGHT = 800; 38 let sX = 0; 39 let sY = 0; // spinX, spinY 40 let pX = 0; 41 let pY = 0; // pixelX, pixelY 42 43 // Legacy 44 if ('detail' in e) { 45 sY = e.detail; 46 } 47 if ('wheelDelta' in e) { 48 sY = -e.wheelDelta / 120; 49 } 50 if ('wheelDeltaY' in e) { 51 sY = -e.wheelDeltaY / 120; 52 } 53 if ('wheelDeltaX' in e) { 54 sX = -e.wheelDeltaX / 120; 55 } 56 57 // side scrolling on FF with DOMMouseScroll 58 if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) { 59 sX = sY; 60 sY = 0; 61 } 62 pX = sX * PIXEL_STEP; 63 pY = sY * PIXEL_STEP; 64 if ('deltaY' in e) { 65 pY = e.deltaY; 66 } 67 if ('deltaX' in e) { 68 pX = e.deltaX; 69 } 70 if (e.shiftKey && !pX) { 71 // if user scrolls with shift he wants horizontal scroll 72 pX = pY; 73 pY = 0; 74 } 75 if ((pX || pY) && e.deltaMode) { 76 if (e.deltaMode === 1) { 77 // delta in LINE units 78 pX *= LINE_HEIGHT; 79 pY *= LINE_HEIGHT; 80 } else { 81 // delta in PAGE units 82 pX *= PAGE_HEIGHT; 83 pY *= PAGE_HEIGHT; 84 } 85 } 86 87 // Fall-back if spin cannot be determined 88 if (pX && !sX) { 89 sX = pX < 1 ? -1 : 1; 90 } 91 if (pY && !sY) { 92 sY = pY < 1 ? -1 : 1; 93 } 94 return { 95 spinX: sX, 96 spinY: sY, 97 pixelX: pX, 98 pixelY: pY 99 }; 100 } 101 function handleMouseEnter() { 102 if (!swiper.enabled) return; 103 swiper.mouseEntered = true; 104 } 105 function handleMouseLeave() { 106 if (!swiper.enabled) return; 107 swiper.mouseEntered = false; 108 } 109 function animateSlider(newEvent) { 110 if (swiper.params.mousewheel.thresholdDelta && newEvent.delta < swiper.params.mousewheel.thresholdDelta) { 111 // Prevent if delta of wheel scroll delta is below configured threshold 112 return false; 113 } 114 if (swiper.params.mousewheel.thresholdTime && now() - lastScrollTime < swiper.params.mousewheel.thresholdTime) { 115 // Prevent if time between scrolls is below configured threshold 116 return false; 117 } 118 119 // If the movement is NOT big enough and 120 // if the last time the user scrolled was too close to the current one (avoid continuously triggering the slider): 121 // Don't go any further (avoid insignificant scroll movement). 122 if (newEvent.delta >= 6 && now() - lastScrollTime < 60) { 123 // Return false as a default 124 return true; 125 } 126 // If user is scrolling towards the end: 127 // If the slider hasn't hit the latest slide or 128 // if the slider is a loop and 129 // if the slider isn't moving right now: 130 // Go to next slide and 131 // emit a scroll event. 132 // Else (the user is scrolling towards the beginning) and 133 // if the slider hasn't hit the first slide or 134 // if the slider is a loop and 135 // if the slider isn't moving right now: 136 // Go to prev slide and 137 // emit a scroll event. 138 if (newEvent.direction < 0) { 139 if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) { 140 swiper.slideNext(); 141 emit('scroll', newEvent.raw); 142 } 143 } else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) { 144 swiper.slidePrev(); 145 emit('scroll', newEvent.raw); 146 } 147 // If you got here is because an animation has been triggered so store the current time 148 lastScrollTime = new window.Date().getTime(); 149 // Return false as a default 150 return false; 151 } 152 function releaseScroll(newEvent) { 153 const params = swiper.params.mousewheel; 154 if (newEvent.direction < 0) { 155 if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) { 156 // Return true to animate scroll on edges 157 return true; 158 } 159 } else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) { 160 // Return true to animate scroll on edges 161 return true; 162 } 163 return false; 164 } 165 function handle(event) { 166 let e = event; 167 let disableParentSwiper = true; 168 if (!swiper.enabled) return; 169 170 // Ignore event if the target or its parents have the swiper-no-mousewheel class 171 if (event.target.closest(`.${swiper.params.mousewheel.noMousewheelClass}`)) return; 172 const params = swiper.params.mousewheel; 173 if (swiper.params.cssMode) { 174 e.preventDefault(); 175 } 176 let targetEl = swiper.el; 177 if (swiper.params.mousewheel.eventsTarget !== 'container') { 178 targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget); 179 } 180 const targetElContainsTarget = targetEl && targetEl.contains(e.target); 181 if (!swiper.mouseEntered && !targetElContainsTarget && !params.releaseOnEdges) return true; 182 if (e.originalEvent) e = e.originalEvent; // jquery fix 183 let delta = 0; 184 const rtlFactor = swiper.rtlTranslate ? -1 : 1; 185 const data = normalize(e); 186 if (params.forceToAxis) { 187 if (swiper.isHorizontal()) { 188 if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = -data.pixelX * rtlFactor;else return true; 189 } else if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = -data.pixelY;else return true; 190 } else { 191 delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? -data.pixelX * rtlFactor : -data.pixelY; 192 } 193 if (delta === 0) return true; 194 if (params.invert) delta = -delta; 195 196 // Get the scroll positions 197 let positions = swiper.getTranslate() + delta * params.sensitivity; 198 if (positions >= swiper.minTranslate()) positions = swiper.minTranslate(); 199 if (positions <= swiper.maxTranslate()) positions = swiper.maxTranslate(); 200 201 // When loop is true: 202 // the disableParentSwiper will be true. 203 // When loop is false: 204 // if the scroll positions is not on edge, 205 // then the disableParentSwiper will be true. 206 // if the scroll on edge positions, 207 // then the disableParentSwiper will be false. 208 disableParentSwiper = swiper.params.loop ? true : !(positions === swiper.minTranslate() || positions === swiper.maxTranslate()); 209 if (disableParentSwiper && swiper.params.nested) e.stopPropagation(); 210 if (!swiper.params.freeMode || !swiper.params.freeMode.enabled) { 211 // Register the new event in a variable which stores the relevant data 212 const newEvent = { 213 time: now(), 214 delta: Math.abs(delta), 215 direction: Math.sign(delta), 216 raw: event 217 }; 218 219 // Keep the most recent events 220 if (recentWheelEvents.length >= 2) { 221 recentWheelEvents.shift(); // only store the last N events 222 } 223 224 const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined; 225 recentWheelEvents.push(newEvent); 226 227 // If there is at least one previous recorded event: 228 // If direction has changed or 229 // if the scroll is quicker than the previous one: 230 // Animate the slider. 231 // Else (this is the first time the wheel is moved): 232 // Animate the slider. 233 if (prevEvent) { 234 if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta || newEvent.time > prevEvent.time + 150) { 235 animateSlider(newEvent); 236 } 237 } else { 238 animateSlider(newEvent); 239 } 240 241 // If it's time to release the scroll: 242 // Return now so you don't hit the preventDefault. 243 if (releaseScroll(newEvent)) { 244 return true; 245 } 246 } else { 247 // Freemode or scrollContainer: 248 249 // If we recently snapped after a momentum scroll, then ignore wheel events 250 // to give time for the deceleration to finish. Stop ignoring after 500 msecs 251 // or if it's a new scroll (larger delta or inverse sign as last event before 252 // an end-of-momentum snap). 253 const newEvent = { 254 time: now(), 255 delta: Math.abs(delta), 256 direction: Math.sign(delta) 257 }; 258 const ignoreWheelEvents = lastEventBeforeSnap && newEvent.time < lastEventBeforeSnap.time + 500 && newEvent.delta <= lastEventBeforeSnap.delta && newEvent.direction === lastEventBeforeSnap.direction; 259 if (!ignoreWheelEvents) { 260 lastEventBeforeSnap = undefined; 261 let position = swiper.getTranslate() + delta * params.sensitivity; 262 const wasBeginning = swiper.isBeginning; 263 const wasEnd = swiper.isEnd; 264 if (position >= swiper.minTranslate()) position = swiper.minTranslate(); 265 if (position <= swiper.maxTranslate()) position = swiper.maxTranslate(); 266 swiper.setTransition(0); 267 swiper.setTranslate(position); 268 swiper.updateProgress(); 269 swiper.updateActiveIndex(); 270 swiper.updateSlidesClasses(); 271 if (!wasBeginning && swiper.isBeginning || !wasEnd && swiper.isEnd) { 272 swiper.updateSlidesClasses(); 273 } 274 if (swiper.params.loop) { 275 swiper.loopFix({ 276 direction: newEvent.direction < 0 ? 'next' : 'prev', 277 byMousewheel: true 278 }); 279 } 280 if (swiper.params.freeMode.sticky) { 281 // When wheel scrolling starts with sticky (aka snap) enabled, then detect 282 // the end of a momentum scroll by storing recent (N=15?) wheel events. 283 // 1. do all N events have decreasing or same (absolute value) delta? 284 // 2. did all N events arrive in the last M (M=500?) msecs? 285 // 3. does the earliest event have an (absolute value) delta that's 286 // at least P (P=1?) larger than the most recent event's delta? 287 // 4. does the latest event have a delta that's smaller than Q (Q=6?) pixels? 288 // If 1-4 are "yes" then we're near the end of a momentum scroll deceleration. 289 // Snap immediately and ignore remaining wheel events in this scroll. 290 // See comment above for "remaining wheel events in this scroll" determination. 291 // If 1-4 aren't satisfied, then wait to snap until 500ms after the last event. 292 clearTimeout(timeout); 293 timeout = undefined; 294 if (recentWheelEvents.length >= 15) { 295 recentWheelEvents.shift(); // only store the last N events 296 } 297 298 const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined; 299 const firstEvent = recentWheelEvents[0]; 300 recentWheelEvents.push(newEvent); 301 if (prevEvent && (newEvent.delta > prevEvent.delta || newEvent.direction !== prevEvent.direction)) { 302 // Increasing or reverse-sign delta means the user started scrolling again. Clear the wheel event log. 303 recentWheelEvents.splice(0); 304 } else if (recentWheelEvents.length >= 15 && newEvent.time - firstEvent.time < 500 && firstEvent.delta - newEvent.delta >= 1 && newEvent.delta <= 6) { 305 // We're at the end of the deceleration of a momentum scroll, so there's no need 306 // to wait for more events. Snap ASAP on the next tick. 307 // Also, because there's some remaining momentum we'll bias the snap in the 308 // direction of the ongoing scroll because it's better UX for the scroll to snap 309 // in the same direction as the scroll instead of reversing to snap. Therefore, 310 // if it's already scrolled more than 20% in the current direction, keep going. 311 const snapToThreshold = delta > 0 ? 0.8 : 0.2; 312 lastEventBeforeSnap = newEvent; 313 recentWheelEvents.splice(0); 314 timeout = nextTick(() => { 315 if (swiper.destroyed || !swiper.params) return; 316 swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold); 317 }, 0); // no delay; move on next tick 318 } 319 320 if (!timeout) { 321 // if we get here, then we haven't detected the end of a momentum scroll, so 322 // we'll consider a scroll "complete" when there haven't been any wheel events 323 // for 500ms. 324 timeout = nextTick(() => { 325 if (swiper.destroyed || !swiper.params) return; 326 const snapToThreshold = 0.5; 327 lastEventBeforeSnap = newEvent; 328 recentWheelEvents.splice(0); 329 swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold); 330 }, 500); 331 } 332 } 333 334 // Emit event 335 if (!ignoreWheelEvents) emit('scroll', e); 336 337 // Stop autoplay 338 if (swiper.params.autoplay && swiper.params.autoplay.disableOnInteraction) swiper.autoplay.stop(); 339 // Return page scroll on edge positions 340 if (params.releaseOnEdges && (position === swiper.minTranslate() || position === swiper.maxTranslate())) { 341 return true; 342 } 343 } 344 } 345 if (e.preventDefault) e.preventDefault();else e.returnValue = false; 346 return false; 347 } 348 function events(method) { 349 let targetEl = swiper.el; 350 if (swiper.params.mousewheel.eventsTarget !== 'container') { 351 targetEl = document.querySelector(swiper.params.mousewheel.eventsTarget); 352 } 353 targetEl[method]('mouseenter', handleMouseEnter); 354 targetEl[method]('mouseleave', handleMouseLeave); 355 targetEl[method]('wheel', handle); 356 } 357 function enable() { 358 if (swiper.params.cssMode) { 359 swiper.wrapperEl.removeEventListener('wheel', handle); 360 return true; 361 } 362 if (swiper.mousewheel.enabled) return false;
vendor: 780 bytes, lines 363-395
363 events('addEventListener'); 364 swiper.mousewheel.enabled = true; 365 return true; 366 } 367 function disable() { 368 if (swiper.params.cssMode) { 369 swiper.wrapperEl.addEventListener(event, handle); 370 return true; 371 } 372 if (!swiper.mousewheel.enabled) return false; 373 events('removeEventListener'); 374 swiper.mousewheel.enabled = false; 375 return true; 376 } 377 on('init', () => { 378 if (!swiper.params.mousewheel.enabled && swiper.params.cssMode) { 379 disable(); 380 } 381 if (swiper.params.mousewheel.enabled) enable(); 382 }); 383 on('destroy', () => { 384 if (swiper.params.cssMode) { 385 enable(); 386 } 387 if (swiper.mousewheel.enabled) disable(); 388 }); 389 Object.assign(swiper.mousewheel, { 390 enable, 391 disable 392 }); 393} 394 395export { Mousewheel as default };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.