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