1(function (global, factory) { 2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 3 typeof define === 'function' && define.amd ? define(factory) : 4 (global = global || self, global.Lenis = factory()); 5 })(this, (function () { 6 function _defineProperties(target, props) { 7 for (var i = 0; i < props.length; i++) { 8 var descriptor = props[i]; 9 descriptor.enumerable = descriptor.enumerable || false; 10 descriptor.configurable = true; 11 if ("value" in descriptor) descriptor.writable = true; 12 Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); 13 } 14 } 15 function _createClass(Constructor, protoProps, staticProps) { 16 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 17 if (staticProps) _defineProperties(Constructor, staticProps); 18 Object.defineProperty(Constructor, "prototype", { 19 writable: false 20 }); 21 return Constructor; 22 } 23 function _extends() { 24 _extends = Object.assign ? Object.assign.bind() : function (target) { 25 for (var i = 1; i < arguments.length; i++) { 26 var source = arguments[i]; 27 for (var key in source) { 28 if (Object.prototype.hasOwnProperty.call(source, key)) { 29 target[key] = source[key]; 30 } 31 } 32 } 33 return target; 34 }; 35 return _extends.apply(this, arguments); 36 } 37 function _toPrimitive(input, hint) { 38 if (typeof input !== "object" || input === null) return input; 39 var prim = input[Symbol.toPrimitive]; 40 if (prim !== undefined) { 41 var res = prim.call(input, hint || "default"); 42 if (typeof res !== "object") return res; 43 throw new TypeError("@@toPrimitive must return a primitive value."); 44 } 45 return (hint === "string" ? String : Number)(input); 46 } 47 function _toPropertyKey(arg) { 48 var key = _toPrimitive(arg, "string"); 49 return typeof key === "symbol" ? key : String(key); 50 } 51 52 var version = "1.0.16"; 53 54 // Clamp a value between a minimum and maximum value 55 function clamp(min, input, max) { 56 return Math.max(min, Math.min(input, max)); 57 } 58 59 // Linearly interpolate between two values using an amount (0 <= t <= 1) 60 function lerp(x, y, t) { 61 return (1 - t) * x + t * y; 62 } 63 64 // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ 65 function damp(x, y, lambda, dt) { 66 return lerp(x, y, 1 - Math.exp(-lambda * dt)); 67 } 68 69 // Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor 70 // https://anguscroll.com/just/just-modulo 71 function modulo(n, d) { 72 return (n % d + d) % d; 73 } 74 75 // Animate class to handle value animations with lerping or easing 76 var Animate = /*#__PURE__*/function () { 77 function Animate() {} 78 var _proto = Animate.prototype; 79 // Advance the animation by the given delta time 80 _proto.advance = function advance(deltaTime) { 81 var _this$onUpdate; 82 if (!this.isRunning) return; 83 var completed = false; 84 if (this.lerp) { 85 this.value = damp(this.value, this.to, this.lerp * 60, deltaTime); 86 if (Math.round(this.value) === this.to) { 87 this.value = this.to; 88 completed = true; 89 } 90 } else { 91 this.currentTime += deltaTime; 92 var linearProgress = clamp(0, this.currentTime / this.duration, 1); 93 completed = linearProgress >= 1; 94 var easedProgress = completed ? 1 : this.easing(linearProgress); 95 this.value = this.from + (this.to - this.from) * easedProgress; 96 } 97 98 // Call the onUpdate callback with the current value and completed status 99 (_this$onUpdate = this.onUpdate) == null ? void 0 : _this$onUpdate.call(this, this.value, { 100 completed: completed 101 }); 102 if (completed) { 103 this.stop(); 104 } 105 } 106 107 // Stop the animation 108 ; 109 _proto.stop = function stop() { 110 this.isRunning = false; 111 } 112 113 // Set up the animation from a starting value to an ending value 114 // with optional parameters for lerping, duration, easing, and onUpdate callback 115 ; 116 _proto.fromTo = function fromTo(from, to, _ref) { 117 var _ref$lerp = _ref.lerp, 118 lerp = _ref$lerp === void 0 ? 0.1 : _ref$lerp, 119 _ref$duration = _ref.duration, 120 duration = _ref$duration === void 0 ? 1 : _ref$duration, 121 _ref$easing = _ref.easing, 122 easing = _ref$easing === void 0 ? function (t) { 123 return t; 124 } : _ref$easing, 125 onUpdate = _ref.onUpdate; 126 this.from = this.value = from; 127 this.to = to; 128 this.lerp = lerp; 129 this.duration = duration; 130 this.easing = easing; 131 this.currentTime = 0; 132 this.isRunning = true; 133 this.onUpdate = onUpdate; 134 }; 135 return Animate; 136 }(); 137 138 function debounce(callback, delay) { 139 var timer; 140 return function () { 141 var args = arguments; 142 var context = this; 143 clearTimeout(timer); 144 timer = setTimeout(function () {
145 callback.apply(context, args); 146 }, delay); 147 }; 148 } 149 150 var Dimensions = /*#__PURE__*/function () { 151 function Dimensions(_temp) { 152 var _this = this; 153 var _ref = _temp === void 0 ? {} : _temp, 154 wrapper = _ref.wrapper, 155 content = _ref.content, 156 _ref$autoResize = _ref.autoResize, 157 autoResize = _ref$autoResize === void 0 ? true : _ref$autoResize; 158 this.resize = function () { 159 _this.onWrapperResize(); 160 _this.onContentResize(); 161 }; 162 this.onWrapperResize = function () { 163 if (_this.wrapper === window) { 164 _this.width = window.innerWidth; 165 _this.height = window.innerHeight; 166 } else { 167 _this.width = _this.wrapper.clientWidth; 168 _this.height = _this.wrapper.clientHeight; 169 } 170 }; 171 this.onContentResize = function () { 172 _this.scrollHeight = _this.content.scrollHeight; 173 _this.scrollWidth = _this.content.scrollWidth; 174 }; 175 this.wrapper = wrapper; 176 this.content = content; 177 if (autoResize) { 178 var resize = debounce(this.resize, 250); 179 if (this.wrapper !== window) { 180 this.wrapperResizeObserver = new ResizeObserver(resize); 181 this.wrapperResizeObserver.observe(this.wrapper); 182 } 183 this.contentResizeObserver = new ResizeObserver(resize); 184 this.contentResizeObserver.observe(this.content); 185 } 186 this.resize(); 187 } 188 var _proto = Dimensions.prototype; 189 _proto.destroy = function destroy() { 190 var _this$wrapperResizeOb, _this$contentResizeOb; 191 (_this$wrapperResizeOb = this.wrapperResizeObserver) == null ? void 0 : _this$wrapperResizeOb.disconnect(); 192 (_this$contentResizeOb = this.contentResizeObserver) == null ? void 0 : _this$contentResizeOb.disconnect(); 193 }; 194 _createClass(Dimensions, [{ 195 key: "limit", 196 get: function get() { 197 return { 198 x: this.scrollWidth - this.width, 199 y: this.scrollHeight - this.height 200 }; 201 } 202 }]); 203 return Dimensions; 204 }(); 205 206 var Emitter = /*#__PURE__*/function () { 207 function Emitter() { 208 this.events = {}; 209 } 210 var _proto = Emitter.prototype; 211 _proto.emit = function emit(event) { 212 var callbacks = this.events[event] || []; 213 for (var i = 0, length = callbacks.length; i < length; i++) { 214 callbacks[i].apply(callbacks, [].slice.call(arguments, 1)); 215 } 216 }; 217 _proto.on = function on(event, cb) { 218 var _this$events$event, 219 _this = this; 220 // Add the callback to the event's callback list, or create a new list with the callback 221 ((_this$events$event = this.events[event]) == null ? void 0 : _this$events$event.push(cb)) || (this.events[event] = [cb]); 222 223 // Return an unsubscribe function 224 return function () { 225 var _this$events$event2; 226 _this.events[event] = (_this$events$event2 = _this.events[event]) == null ? void 0 : _this$events$event2.filter(function (i) { 227 return cb !== i; 228 }); 229 }; 230 }; 231 _proto.destroy = function destroy() { 232 this.events = {}; 233 }; 234 return Emitter; 235 }(); 236 237 var VirtualScroll = /*#__PURE__*/function () { 238 function VirtualScroll(element, _ref) { 239 var _this = this; 240 var _ref$wheelMultiplier = _ref.wheelMultiplier, 241 wheelMultiplier = _ref$wheelMultiplier === void 0 ? 1 : _ref$wheelMultiplier, 242 _ref$touchMultiplier = _ref.touchMultiplier, 243 touchMultiplier = _ref$touchMultiplier === void 0 ? 2 : _ref$touchMultiplier, 244 _ref$normalizeWheel = _ref.normalizeWheel, 245 normalizeWheel = _ref$normalizeWheel === void 0 ? false : _ref$normalizeWheel; 246 // Event handler for 'touchstart' event 247 this.onTouchStart = function (event) { 248 var _ref2 = event.targetTouches ? event.targetTouches[0] : event, 249 clientX = _ref2.clientX, 250 clientY = _ref2.clientY; 251 _this.touchStart.x = clientX; 252 _this.touchStart.y = clientY; 253 _this.lastDelta = { 254 x: 0, 255 y: 0 256 }; 257 }; 258 // Event handler for 'touchmove' event 259 this.onTouchMove = function (event) { 260 var _ref3 = event.targetTouches ? event.targetTouches[0] : event, 261 clientX = _ref3.clientX, 262 clientY = _ref3.clientY; 263 var deltaX = -(clientX - _this.touchStart.x) * _this.touchMultiplier; 264 var deltaY = -(clientY - _this.touchStart.y) * _this.touchMultiplier; 265 _this.touchStart.x = clientX; 266 _this.touchStart.y = clientY; 267 _this.lastDelta = { 268 x: deltaX, 269 y: deltaY 270 }; 271 _this.emitter.emit('scroll', { 272 type: 'touch', 273 deltaX: deltaX, 274 deltaY: deltaY, 275 event: event 276 }); 277 }; 278 this.onTouchEnd = function (event) { 279 _this.emitter.emit('scroll', { 280 type: 'touch', 281 inertia: true, 282 deltaX: _this.lastDelta.x, 283 deltaY: _this.lastDelta.y, 284 event: event 285 }); 286 }; 287 // Event handler for 'wheel' event 288 this.onWheel = function (event) { 289 var deltaX = event.deltaX, 290 deltaY = event.deltaY; 291 if (_this.normalizeWheel) { 292 deltaX = clamp(-100, deltaX, 100); 293 deltaY = clamp(-100, deltaY, 100); 294 } 295 deltaX *= _this.wheelMultiplier; 296 deltaY *= _this.wheelMultiplier; 297 _this.emitter.emit('scroll', { 298 type: 'wheel', 299 deltaX: deltaX, 300 deltaY: deltaY, 301 event: event 302 }); 303 }; 304 this.element = element; 305 this.wheelMultiplier = wheelMultiplier; 306 this.touchMultiplier = touchMultiplier; 307 this.normalizeWheel = normalizeWheel; 308 this.touchStart = { 309 x: null, 310 y: null 311 }; 312 this.emitter = new Emitter(); 313 this.element.addEventListener('wheel', this.onWheel, { 314 passive: false 315 }); 316 this.element.addEventListener('touchstart', this.onTouchStart, { 317 passive: false 318 }); 319 this.element.addEventListener('touchmove', this.onTouchMove, { 320 passive: false 321 }); 322 this.element.addEventListener('touchend', this.onTouchEnd, { 323 passive: false 324 }); 325 } 326 327 // Add an event listener for the given event and callback 328 var _proto = VirtualScroll.prototype; 329 _proto.on = function on(event, callback) { 330 return this.emitter.on(event, callback); 331 } 332 333 // Remove all event listeners and clean up 334 ; 335 _proto.destroy = function destroy() { 336 this.emitter.destroy(); 337 this.element.removeEventListener('wheel', this.onWheel, { 338 passive: false 339 }); 340 this.element.removeEventListener('touchstart', this.onTouchStart, { 341 passive: false 342 }); 343 this.element.removeEventListener('touchmove', this.onTouchMove, { 344 passive: false 345 }); 346 this.element.removeEventListener('touchend', this.onTouchEnd, { 347 passive: false 348 }); 349 }; 350 return VirtualScroll; 351 }(); 352 353 // Technical explaination 354 // - listen to 'wheel' events 355 // - prevent 'wheel' event to prevent scroll 356 // - normalize wheel delta 357 // - add delta to targetScroll 358 // - animate scroll to targetScroll (smooth context) 359 // - if animation is not running, listen to 'scroll' events (native context) 360 var Lenis = /*#__PURE__*/function () { 361 // isScrolling = true when scroll is animating 362 // isStopped = true if user should not be able to scroll - enable/disable programatically 363 // isSmooth = true if scroll should be animated
364 // isLocked = same as isStopped but enabled/disabled when scroll reaches target 365 366 /** 367 * @typedef {(t: number) => number} EasingFunction 368 * @typedef {'vertical' | 'horizontal'} Orientation 369 * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation 370 * 371 * @typedef LenisOptions 372 * @property {Orientation} [direction] 373 * @property {GestureOrientation} [gestureDirection] 374 * @property {number} [mouseMultiplier] 375 * @property {boolean} [smooth] 376 * 377 * @property {Window | HTMLElement} [wrapper] 378 * @property {HTMLElement} [content] 379 * @property {Window | HTMLElement} [wheelEventsTarget] 380 * @property {boolean} [smoothWheel] 381 * @property {boolean} [smoothTouch] 382 * @property {boolean} [syncTouch] 383 * @property {number} [syncTouchLerp] 384 * @property {number} [touchInertiaMultiplier] 385 * @property {number} [duration] 386 * @property {EasingFunction} [easing] 387 * @property {number} [lerp] 388 * @property {boolean} [infinite] 389 * @property {Orientation} [orientation] 390 * @property {GestureOrientation} [gestureOrientation] 391 * @property {number} [touchMultiplier] 392 * @property {number} [wheelMultiplier] 393 * @property {boolean} [normalizeWheel] 394 * @property {boolean} [autoResize] 395 * 396 * @param {LenisOptions} 397 */ 398 function Lenis(_temp) { 399 var _this = this; 400 var _ref = _temp === void 0 ? {} : _temp, 401 _ref$wrapper = _ref.wrapper, 402 wrapper = _ref$wrapper === void 0 ? window : _ref$wrapper, 403 _ref$content = _ref.content, 404 content = _ref$content === void 0 ? document.documentElement : _ref$content, 405 _ref$wheelEventsTarge = _ref.wheelEventsTarget, 406 wheelEventsTarget = _ref$wheelEventsTarge === void 0 ? wrapper : _ref$wheelEventsTarge, 407 _ref$smoothWheel = _ref.smoothWheel, 408 smoothWheel = _ref$smoothWheel === void 0 ? true : _ref$smoothWheel, 409 _ref$smoothTouch = _ref.smoothTouch, 410 smoothTouch = _ref$smoothTouch === void 0 ? false : _ref$smoothTouch, 411 _ref$syncTouch = _ref.syncTouch, 412 _syncTouch = _ref$syncTouch === void 0 ? false : _ref$syncTouch, 413 _ref$syncTouchLerp = _ref.syncTouchLerp, 414 syncTouchLerp = _ref$syncTouchLerp === void 0 ? 0.1 : _ref$syncTouchLerp, 415 _ref$__iosNoInertiaSy = _ref.__iosNoInertiaSyncTouchLerp, 416 __iosNoInertiaSyncTouchLerp = _ref$__iosNoInertiaSy === void 0 ? 0.4 : _ref$__iosNoInertiaSy, 417 _ref$touchInertiaMult = _ref.touchInertiaMultiplier, 418 touchInertiaMultiplier = _ref$touchInertiaMult === void 0 ? 35 : _ref$touchInertiaMult, 419 duration = _ref.duration, 420 _ref$easing = _ref.easing, 421 easing = _ref$easing === void 0 ? function (t) { 422 return Math.min(1, 1.001 - Math.pow(2, -10 * t)); 423 } : _ref$easing, 424 _ref$lerp = _ref.lerp, 425 lerp = _ref$lerp === void 0 ? duration && 0.1 : _ref$lerp, 426 _ref$infinite = _ref.infinite, 427 infinite = _ref$infinite === void 0 ? false : _ref$infinite, 428 _ref$orientation = _ref.orientation, 429 orientation = _ref$orientation === void 0 ? 'vertical' : _ref$orientation, 430 _ref$gestureOrientati = _ref.gestureOrientation, 431 gestureOrientation = _ref$gestureOrientati === void 0 ? 'vertical' : _ref$gestureOrientati, 432 _ref$touchMultiplier = _ref.touchMultiplier, 433 touchMultiplier = _ref$touchMultiplier === void 0 ? 1 : _ref$touchMultiplier, 434 _ref$wheelMultiplier = _ref.wheelMultiplier, 435 wheelMultiplier = _ref$wheelMultiplier === void 0 ? 1 : _ref$wheelMultiplier, 436 _ref$normalizeWheel = _ref.normalizeWheel, 437 normalizeWheel = _ref$normalizeWheel === void 0 ? false : _ref$normalizeWheel, 438 _ref$autoResize = _ref.autoResize, 439 autoResize = _ref$autoResize === void 0 ? true : _ref$autoResize; 440 this.onVirtualScroll = function (_ref2) { 441 var type = _ref2.type, 442 inertia = _ref2.inertia, 443 deltaX = _ref2.deltaX, 444 deltaY = _ref2.deltaY, 445 event = _ref2.event; 446 // keep zoom feature 447 if (event.ctrlKey) return; 448 var isTouch = type === 'touch'; 449 var isWheel = type === 'wheel'; 450 if (_this.options.gestureOrientation === 'vertical' && deltaY === 0 || 451 // trackpad previous/next page gesture 452 _this.options.gestureOrientation === 'horizontal' && deltaX === 0 || isTouch && _this.options.gestureOrientation === 'vertical' && _this.scroll === 0 && !_this.options.infinite && deltaY <= 0 // touch pull to refresh 453 ) return; 454 455 // catch if scrolling on nested scroll elements 456 if (!!event.composedPath().find(function (node) { 457 return (node == null ? void 0 : node.hasAttribute == null ? void 0 : node.hasAttribute('data-lenis-prevent')) || isTouch && (node == null ? void 0 : node.hasAttribute == null ? void 0 : node.hasAttribute('data-lenis-prevent-touch')) || isWheel && (node == null ? void 0 : node.hasAttribute == null ? void 0 : node.hasAttribute('data-lenis-prevent-wheel')); 458 })) return; 459 if (_this.isStopped || _this.isLocked) { 460 event.preventDefault(); 461 return; 462 } 463 _this.isSmooth = (_this.options.smoothTouch || _this.options.syncTouch) && isTouch || _this.options.smoothWheel && isWheel; 464 if (!_this.isSmooth) { 465 _this.isScrolling = false; 466 _this.animate.stop(); 467 return; 468 } 469 event.preventDefault(); 470 var delta = deltaY; 471 if (_this.options.gestureOrientation === 'both') { 472 delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX; 473 } else if (_this.options.gestureOrientation === 'horizontal') { 474 delta = deltaX; 475 } 476 var syncTouch = isTouch && _this.options.syncTouch; 477 var hasTouchInertia = isTouch && inertia && Math.abs(delta) > 1; 478 if (hasTouchInertia) { 479 delta = _this.velocity * _this.options.touchInertiaMultiplier; 480 } 481 _this.scrollTo(_this.targetScroll + delta, _extends({ 482 programmatic: false 483 }, syncTouch && { 484 lerp: hasTouchInertia ? _this.syncTouchLerp : _this.options.__iosNoInertiaSyncTouchLerp 485 })); 486 }; 487 this.onScroll = function () { 488 if (!_this.isScrolling) { 489 var lastScroll = _this.animatedScroll; 490 _this.animatedScroll = _this.targetScroll = _this.actualScroll; 491 _this.velocity = 0; 492 _this.direction = Math.sign(_this.animatedScroll - lastScroll);
493 _this.emit(); 494 } 495 }; 496 window.lenisVersion = version; 497 498 // if wrapper is html or body, fallback to window 499 if (wrapper === document.documentElement || wrapper === document.body) { 500 wrapper = window; 501 } 502 this.options = { 503 wrapper: wrapper, 504 content: content, 505 wheelEventsTarget: wheelEventsTarget, 506 smoothWheel: smoothWheel, 507 smoothTouch: smoothTouch, 508 syncTouch: _syncTouch, 509 syncTouchLerp: syncTouchLerp, 510 __iosNoInertiaSyncTouchLerp: __iosNoInertiaSyncTouchLerp, 511 touchInertiaMultiplier: touchInertiaMultiplier, 512 duration: duration, 513 easing: easing, 514 lerp: lerp, 515 infinite: infinite, 516 gestureOrientation: gestureOrientation, 517 orientation: orientation, 518 touchMultiplier: touchMultiplier, 519 wheelMultiplier: wheelMultiplier, 520 normalizeWheel: normalizeWheel, 521 autoResize: autoResize 522 }; 523 this.dimensions = new Dimensions({ 524 wrapper: wrapper, 525 content: content, 526 autoResize: autoResize 527 }); 528 this.rootElement.classList.add('lenis'); 529 this.velocity = 0; 530 this.isStopped = false; 531 this.isSmooth = smoothWheel || smoothTouch; 532 this.isScrolling = false; 533 this.targetScroll = this.animatedScroll = this.actualScroll; 534 this.animate = new Animate(); 535 this.emitter = new Emitter(); 536 this.options.wrapper.addEventListener('scroll', this.onScroll, { 537 passive: false 538 }); 539 this.virtualScroll = new VirtualScroll(wheelEventsTarget, { 540 touchMultiplier: touchMultiplier, 541 wheelMultiplier: wheelMultiplier, 542 normalizeWheel: normalizeWheel 543 }); 544 this.virtualScroll.on('scroll', this.onVirtualScroll); 545 } 546 var _proto = Lenis.prototype; 547 _proto.destroy = function destroy() { 548 this.emitter.destroy(); 549 this.options.wrapper.removeEventListener('scroll', this.onScroll, { 550 passive: false 551 }); 552 this.virtualScroll.destroy(); 553 this.dimensions.destroy(); 554 this.rootElement.classList.remove('lenis'); 555 this.rootElement.classList.remove('lenis-smooth'); 556 this.rootElement.classList.remove('lenis-scrolling'); 557 this.rootElement.classList.remove('lenis-stopped'); 558 }; 559 _proto.on = function on(event, callback) { 560 return this.emitter.on(event, callback); 561 }; 562 _proto.off = function off(event, callback) { 563 var _this$emitter$events$; 564 this.emitter.events[event] = (_this$emitter$events$ = this.emitter.events[event]) == null ? void 0 : _this$emitter$events$.filter(function (i) { 565 return callback !== i; 566 }); 567 }; 568 _proto.setScroll = function setScroll(scroll) { 569 // apply scroll value immediately 570 if (this.isHorizontal) { 571 this.rootElement.scrollLeft = scroll; 572 } else { 573 this.rootElement.scrollTop = scroll; 574 } 575 }; 576 _proto.resize = function resize() { 577 this.dimensions.resize(); 578 }; 579 _proto.emit = function emit() { 580 this.emitter.emit('scroll', this); 581 }; 582 _proto.reset = function reset() { 583 this.isLocked = false; 584 this.isScrolling = false; 585 this.velocity = 0; 586 this.animate.stop(); 587 }; 588 _proto.start = function start() { 589 this.isStopped = false; 590 this.reset(); 591 }; 592 _proto.stop = function stop() { 593 this.isStopped = true; 594 this.animate.stop(); 595 this.reset(); 596 }; 597 _proto.raf = function raf(time) { 598 var deltaTime = time - (this.time || time); 599 this.time = time; 600 this.animate.advance(deltaTime * 0.001); 601 }; 602 _proto.scrollTo = function scrollTo(target, _temp2) { 603 var _this2 = this; 604 var _ref3 = _temp2 === void 0 ? {}
604 : _temp2, 605 _ref3$offset = _ref3.offset, 606 offset = _ref3$offset === void 0 ? 0 : _ref3$offset, 607 _ref3$immediate = _ref3.immediate, 608 immediate = _ref3$immediate === void 0 ? false : _ref3$immediate, 609 _ref3$lock = _ref3.lock, 610 lock = _ref3$lock === void 0 ? false : _ref3$lock, 611 _ref3$duration = _ref3.duration, 612 duration = _ref3$duration === void 0 ? this.options.duration : _ref3$duration, 613 _ref3$easing = _ref3.easing, 614 easing = _ref3$easing === void 0 ? this.options.easing : _ref3$easing, 615 _ref3$lerp = _ref3.lerp, 616 lerp = _ref3$lerp === void 0 ? !duration && this.options.lerp : _ref3$lerp, 617 _ref3$onComplete = _ref3.onComplete, 618 onComplete = _ref3$onComplete === void 0 ? null : _ref3$onComplete, 619 _ref3$force = _ref3.force, 620 force = _ref3$force === void 0 ? false : _ref3$force, 621 _ref3$programmatic = _ref3.programmatic, 622 programmatic = _ref3$programmatic === void 0 ? true : _ref3$programmatic; 623 if (this.isStopped && !force) return; 624 625 // keywords 626 if (['top', 'left', 'start'].includes(target)) { 627 target = 0; 628 } else if (['bottom', 'right', 'end'].includes(target)) { 629 target = this.limit; 630 } else { 631 var _target; 632 var node; 633 if (typeof target === 'string') { 634 // CSS selector 635 node = document.querySelector(target); 636 } else if ((_target = target) != null && _target.nodeType) { 637 // Node element 638 node = target; 639 } 640 if (node) { 641 if (this.options.wrapper !== window) { 642 // nested scroll offset correction 643 var wrapperRect = this.options.wrapper.getBoundingClientRect(); 644 offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top; 645 } 646 var rect = node.getBoundingClientRect(); 647 target = (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll; 648 } 649 } 650 if (typeof target !== 'number') return; 651 target += offset; 652 target = Math.round(target); 653 if (this.options.infinite) { 654 if (programmatic) { 655 this.targetScroll = this.animatedScroll = this.scroll; 656 } 657 } else { 658 target = clamp(0, target, this.limit); 659 } 660 if (immediate) { 661 this.animatedScroll = this.targetScroll = target; 662 this.setScroll(this.scroll); 663 this.reset(); 664 this.emit(); 665 onComplete == null ? void 0 : onComplete(); 666 return; 667 } 668 if (!programmatic) { 669 if (target === this.targetScroll) return; 670 this.targetScroll = target; 671 } 672 this.animate.fromTo(this.animatedScroll, target, { 673 duration: duration, 674 easing: easing, 675 lerp: lerp, 676 onUpdate: function onUpdate(value, _ref4) { 677 var completed = _ref4.completed; 678 // started 679 if (lock) _this2.isLocked = true; 680 _this2.isScrolling = true; 681 682 // updated 683 _this2.velocity = value - _this2.animatedScroll; 684 _this2.direction = Math.sign(_this2.velocity); 685 _this2.animatedScroll = value; 686 _this2.setScroll(_this2.scroll); 687 if (programmatic) { 688 // wheel during programmatic should stop it 689 _this2.targetScroll = value; 690 } 691 692 // completed 693 if (completed) { 694 if (lock) _this2.isLocked = false; 695 requestAnimationFrame(function () { 696 //avoid double scroll event 697 _this2.isScrolling = false; 698 }); 699 _this2.velocity = 0; 700 onComplete == null ? void 0 : onComplete(); 701 } 702 _this2.emit(); 703 } 704 }); 705 }; 706 _createClass(Lenis, [{ 707 key: "rootElement", 708 get: function get() { 709 return this.options.wrapper === window ? this.options.content : this.options.wrapper; 710 } 711 }, { 712 key: "limit", 713 get: function get() { 714 return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']; 715 } 716 }, { 717 key: "isHorizontal", 718 get: function get() { 719 return this.options.orientation === 'horizontal'; 720 } 721 }, { 722 key: "actualScroll", 723 get: function get() { 724 // value browser takes into account 725 return this.isHorizontal ? this.rootElement.scrollLeft : this.rootElement.scrollTop; 726 } 727 }, { 728 key: "scroll", 729 get: function get() { 730 return this.options.infinite ? modulo(this.animatedScroll, this.limit) : this.animatedScroll; 731 } 732 }, { 733 key: "progress", 734 get: function get() { 735 // avoid progress to be NaN 736 return this.limit === 0 ? 1 : this.scroll / this.limit; 737 } 738 }, { 739 key: "isSmooth", 740 get: function get() { 741 return this.__isSmooth; 742 }, 743 set: function set(value) { 744 if (this.__isSmooth !== value) { 745 this.rootElement.classList.toggle('lenis-smooth', value); 746 this.__isSmooth = value; 747 } 748 } 749 }, { 750 key: "isScrolling", 751 get: function get() { 752 return this.__isScrolling; 753 }, 754 set: function set(value) { 755 if (this.__isScrolling !== value) { 756 this.rootElement.classList.toggle('lenis-scrolling', value); 757 this.__isScrolling = value; 758 } 759 } 760 }, { 761 key: "isStopped", 762 get: function get() { 763 return this.__isStopped; 764 }, 765 set: function set(value) { 766 if (this.__isStopped !== value) { 767 this.rootElement.classList.toggle('lenis-stopped', value); 768 this.__isStopped = value; 769 } 770 } 771 }]); 772 return Lenis; 773 }(); 774 775 return Lenis; 776 777 })); 778
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.