vevet 2.0.1-dev.8 → 2.0.6
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/build/cdn/index.js +1 -1
- package/build/cjs/app/Application.js +12 -8
- package/build/cjs/app/events/PageLoad.js +3 -3
- package/build/cjs/app/events/Viewport.js +5 -5
- package/build/cjs/base/Callbacks.js +3 -3
- package/build/cjs/base/Module.js +16 -7
- package/build/cjs/base/MutableProp.js +10 -10
- package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
- package/build/cjs/components/canvas/Ctx2D.js +7 -3
- package/build/cjs/components/canvas/Ctx2DPrerender.js +21 -3
- package/build/cjs/components/cursor/CustomCursor.js +12 -12
- package/build/cjs/components/dragger/Dragger.js +8 -8
- package/build/cjs/components/dragger/DraggerMove.js +2 -2
- package/build/cjs/components/loading/Preloader.js +5 -5
- package/build/cjs/components/loading/ProgressPreloader.js +17 -5
- package/build/cjs/components/page/Page.js +37 -9
- package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +2 -2
- package/build/cjs/components/scroll/scrollable/ScrollEventsBase.js +1 -1
- package/build/cjs/components/scroll/scrollable/ScrollView.js +133 -73
- package/build/cjs/components/scroll/scrollbar/Bar.js +18 -15
- package/build/cjs/components/scroll/scrollbar/ScrollBar.js +9 -7
- package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +26 -22
- package/build/cjs/components/text/SplitText.js +47 -12
- package/build/cjs/components/timeline/StaticTimeline.js +4 -4
- package/build/cjs/components/timeline/Timeline.js +2 -2
- package/build/cjs/handlers/wheel/WheelHandler.js +4 -4
- package/build/cjs/utils/common/mergeWithoutArrays.js +1 -1
- package/build/cjs/utils/common/randID.js +2 -2
- package/build/cjs/utils/listeners/onScroll.js +66 -28
- package/build/cjs/utils/math/{boundVal.js → clamp.js} +3 -3
- package/build/cjs/utils/math/clampScope.js +16 -0
- package/build/cjs/utils/math/inScope.js +10 -0
- package/build/cjs/utils/math/index.js +13 -7
- package/build/cjs/utils/math/scoped.js +18 -0
- package/build/cjs/utils/math/{spreadScopeProgress.js → spreadScope.js} +2 -2
- package/build/cjs/utils/math/wrap.js +13 -0
- package/build/es/app/Application.js +4 -0
- package/build/es/base/Module.js +2 -4
- package/build/es/components/animation-frame/AnimationFrame.js +2 -2
- package/build/es/components/canvas/Ctx2D.js +6 -2
- package/build/es/components/canvas/Ctx2DPrerender.js +20 -2
- package/build/es/components/loading/ProgressPreloader.js +14 -2
- package/build/es/components/page/Page.js +32 -8
- package/build/es/components/scroll/scrollable/ScrollView.js +112 -62
- package/build/es/components/scroll/scrollbar/Bar.js +9 -6
- package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
- package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +13 -9
- package/build/es/components/text/SplitText.js +38 -3
- package/build/es/components/timeline/StaticTimeline.js +3 -3
- package/build/es/components/timeline/Timeline.js +2 -2
- package/build/es/utils/listeners/onScroll.js +65 -28
- package/build/es/utils/math/{boundVal.js → clamp.js} +2 -2
- package/build/es/utils/math/clampScope.js +8 -0
- package/build/es/utils/math/inScope.js +6 -0
- package/build/es/utils/math/index.js +7 -4
- package/build/es/utils/math/scoped.js +14 -0
- package/build/es/utils/math/{spreadScopeProgress.js → spreadScope.js} +1 -1
- package/build/es/utils/math/wrap.js +10 -0
- package/build/types/app/Application.d.ts +1 -0
- package/build/types/app/Application.d.ts.map +1 -1
- package/build/types/base/Module.d.ts.map +1 -1
- package/build/types/components/canvas/Ctx2D.d.ts +9 -0
- package/build/types/components/canvas/Ctx2D.d.ts.map +1 -1
- package/build/types/components/canvas/Ctx2DPrerender.d.ts +1 -1
- package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -1
- package/build/types/components/loading/ProgressPreloader.d.ts +7 -0
- package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
- package/build/types/components/page/Page.d.ts +2 -0
- package/build/types/components/page/Page.d.ts.map +1 -1
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +40 -14
- package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
- package/build/types/components/scroll/scrollbar/Bar.d.ts.map +1 -1
- package/build/types/components/scroll/scrollbar/ScrollBar.d.ts +4 -0
- package/build/types/components/scroll/scrollbar/ScrollBar.d.ts.map +1 -1
- package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts +4 -0
- package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts.map +1 -1
- package/build/types/components/text/SplitText.d.ts +10 -0
- package/build/types/components/text/SplitText.d.ts.map +1 -1
- package/build/types/utils/listeners/onScroll.d.ts +10 -6
- package/build/types/utils/listeners/onScroll.d.ts.map +1 -1
- package/build/types/utils/math/clamp.d.ts +5 -0
- package/build/types/utils/math/clamp.d.ts.map +1 -0
- package/build/types/utils/math/clampScope.d.ts +5 -0
- package/build/types/utils/math/clampScope.d.ts.map +1 -0
- package/build/types/utils/math/inScope.d.ts +5 -0
- package/build/types/utils/math/inScope.d.ts.map +1 -0
- package/build/types/utils/math/index.d.ts +7 -4
- package/build/types/utils/math/index.d.ts.map +1 -1
- package/build/types/utils/math/scoped.d.ts +12 -0
- package/build/types/utils/math/scoped.d.ts.map +1 -0
- package/build/types/utils/math/spreadScope.d.ts +5 -0
- package/build/types/utils/math/spreadScope.d.ts.map +1 -0
- package/build/types/utils/math/wrap.d.ts +5 -0
- package/build/types/utils/math/wrap.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/ts/app/Application.ts +6 -0
- package/src/ts/base/Module.ts +5 -4
- package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
- package/src/ts/components/canvas/Ctx2D.ts +16 -1
- package/src/ts/components/canvas/Ctx2DPrerender.ts +23 -6
- package/src/ts/components/loading/ProgressPreloader.ts +21 -2
- package/src/ts/components/page/Page.ts +34 -8
- package/src/ts/components/scroll/scrollable/ScrollView.ts +155 -86
- package/src/ts/components/scroll/scrollbar/Bar.ts +9 -6
- package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
- package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +17 -8
- package/src/ts/components/text/SplitText.ts +52 -2
- package/src/ts/components/timeline/StaticTimeline.ts +4 -4
- package/src/ts/components/timeline/Timeline.ts +2 -2
- package/src/ts/utils/listeners/onScroll.ts +101 -38
- package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
- package/src/ts/utils/math/clampScope.ts +16 -0
- package/src/ts/utils/math/inScope.ts +9 -0
- package/src/ts/utils/math/index.ts +12 -6
- package/src/ts/utils/math/scoped.ts +17 -0
- package/src/ts/utils/math/{spreadScopeProgress.ts → spreadScope.ts} +2 -2
- package/src/ts/utils/math/wrap.ts +18 -0
- package/build/cjs/components/scroll/custom-scroll/CustomScroll.js +0 -517
- package/build/cjs/components/split-text/SplitText.js +0 -233
- package/build/cjs/utils/math/scopeProgress.js +0 -25
- package/build/es/components/scroll/custom-scroll/CustomScroll.js +0 -486
- package/build/es/components/split-text/SplitText.js +0 -199
- package/build/es/utils/math/scopeProgress.js +0 -22
- package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts +0 -322
- package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts.map +0 -1
- package/build/types/components/split-text/SplitText.d.ts +0 -118
- package/build/types/components/split-text/SplitText.d.ts.map +0 -1
- package/build/types/utils/math/boundVal.d.ts +0 -5
- package/build/types/utils/math/boundVal.d.ts.map +0 -1
- package/build/types/utils/math/scopeProgress.d.ts +0 -20
- package/build/types/utils/math/scopeProgress.d.ts.map +0 -1
- package/build/types/utils/math/spreadScopeProgress.d.ts +0 -5
- package/build/types/utils/math/spreadScopeProgress.d.ts.map +0 -1
- package/src/ts/utils/math/scopeProgress.ts +0 -23
|
@@ -6,7 +6,7 @@ import { Component, NComponent } from '../../../base/Component';
|
|
|
6
6
|
import { RequiredModuleProp } from '../../../utils/types/utility';
|
|
7
7
|
import { AnimationFrame } from '../../animation-frame/AnimationFrame';
|
|
8
8
|
import { ScrollableElement } from '../types';
|
|
9
|
-
import
|
|
9
|
+
import clamp from '../../../utils/math/clamp';
|
|
10
10
|
import { NCallbacks } from '../../../base/Callbacks';
|
|
11
11
|
import { lerp } from '../../../utils/math';
|
|
12
12
|
|
|
@@ -41,6 +41,10 @@ export namespace NSmoothScroll {
|
|
|
41
41
|
* @default false
|
|
42
42
|
*/
|
|
43
43
|
animationFrame?: false | AnimationFrame;
|
|
44
|
+
/**
|
|
45
|
+
* @default 0
|
|
46
|
+
*/
|
|
47
|
+
resizeTimeout?: number;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
/**
|
|
@@ -215,7 +219,7 @@ export class SmoothScroll <
|
|
|
215
219
|
? -this.prop.overscroll.max : 0;
|
|
216
220
|
const max = this.maxScrollableWidth
|
|
217
221
|
+ (!!this.prop.overscroll && this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
218
|
-
this._targetLeft =
|
|
222
|
+
this._targetLeft = clamp(
|
|
219
223
|
val,
|
|
220
224
|
[min, max],
|
|
221
225
|
);
|
|
@@ -247,7 +251,7 @@ export class SmoothScroll <
|
|
|
247
251
|
? -this.prop.overscroll.max : 0;
|
|
248
252
|
const max = this.maxScrollableHeight
|
|
249
253
|
+ (!!this.prop.overscroll && !this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
250
|
-
this._targetTop =
|
|
254
|
+
this._targetTop = clamp(
|
|
251
255
|
val,
|
|
252
256
|
[min, max],
|
|
253
257
|
);
|
|
@@ -401,9 +405,11 @@ export class SmoothScroll <
|
|
|
401
405
|
}
|
|
402
406
|
this._elementsLength = this._elements.length;
|
|
403
407
|
// add will-change
|
|
404
|
-
this.
|
|
405
|
-
|
|
406
|
-
|
|
408
|
+
if (this.prop.useWillChange) {
|
|
409
|
+
this._elements.forEach((el) => {
|
|
410
|
+
el.style.willChange = 'transform';
|
|
411
|
+
});
|
|
412
|
+
}
|
|
407
413
|
|
|
408
414
|
// initialize the class
|
|
409
415
|
if (init) {
|
|
@@ -423,6 +429,7 @@ export class SmoothScroll <
|
|
|
423
429
|
enabled: true,
|
|
424
430
|
animationFrame: false,
|
|
425
431
|
recalculateSizes: true,
|
|
432
|
+
resizeTimeout: 0,
|
|
426
433
|
useWheel: true,
|
|
427
434
|
autoStop: true,
|
|
428
435
|
isHorizontal: false,
|
|
@@ -453,6 +460,8 @@ export class SmoothScroll <
|
|
|
453
460
|
this.resize();
|
|
454
461
|
this.addViewportCallback('', () => {
|
|
455
462
|
this.resize(true);
|
|
463
|
+
}, {
|
|
464
|
+
timeout: this.prop.resizeTimeout,
|
|
456
465
|
});
|
|
457
466
|
|
|
458
467
|
// wheel
|
|
@@ -490,8 +499,8 @@ export class SmoothScroll <
|
|
|
490
499
|
// get sizes
|
|
491
500
|
this._clientWidth = outer.clientWidth;
|
|
492
501
|
this._clientHeight = outer.clientHeight;
|
|
493
|
-
this._scrollWidth =
|
|
494
|
-
this._scrollHeight =
|
|
502
|
+
this._scrollWidth = clamp(container.clientWidth, [this.clientWidth, Infinity]);
|
|
503
|
+
this._scrollHeight = clamp(container.clientHeight, [this.clientHeight, Infinity]);
|
|
495
504
|
|
|
496
505
|
// force instant change
|
|
497
506
|
// it means that after resizing, scrolling will be instantaneous for a while
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createElement, selectOne } from 'vevet-dom';
|
|
2
|
+
import { NViewport } from '../../app/events/Viewport';
|
|
2
3
|
import { Component, NComponent } from '../../base/Component';
|
|
3
4
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
4
5
|
|
|
@@ -25,6 +26,15 @@ export namespace NSplitText {
|
|
|
25
26
|
* @default false
|
|
26
27
|
*/
|
|
27
28
|
appendLines?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Viewport resize event target
|
|
31
|
+
* @default ''
|
|
32
|
+
*/
|
|
33
|
+
viewportTarget?: keyof NViewport.CallbacksTypes;
|
|
34
|
+
/**
|
|
35
|
+
* @default 0
|
|
36
|
+
*/
|
|
37
|
+
resizeTimeout?: number;
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
/**
|
|
@@ -84,6 +94,8 @@ export class SplitText <
|
|
|
84
94
|
container: `#${this.prefix}`,
|
|
85
95
|
appendLetters: true,
|
|
86
96
|
appendLines: false,
|
|
97
|
+
viewportTarget: '',
|
|
98
|
+
resizeTimeout: 0,
|
|
87
99
|
};
|
|
88
100
|
}
|
|
89
101
|
|
|
@@ -153,8 +165,12 @@ export class SplitText <
|
|
|
153
165
|
|
|
154
166
|
// get initial text
|
|
155
167
|
this._initHTML = this._container.innerHTML;
|
|
156
|
-
|
|
168
|
+
const innerText = this._container.innerText.trim() || this._container.innerHTML.trim();
|
|
169
|
+
this._initText = innerText || 'no rendered text';
|
|
157
170
|
this._initText = this._initText.replace(/\s+\n/gm, '\n');
|
|
171
|
+
this._initText = this._initText.replace(/<br>/gm, String.fromCharCode(10));
|
|
172
|
+
this._initText = this._initText.replace(/<br\/>/gm, String.fromCharCode(10));
|
|
173
|
+
this._initText = this._initText.replace(/<br \/>/gm, String.fromCharCode(10));
|
|
158
174
|
|
|
159
175
|
// set default vars
|
|
160
176
|
this._isPrimarySplit = false;
|
|
@@ -174,8 +190,10 @@ export class SplitText <
|
|
|
174
190
|
// split the text
|
|
175
191
|
this.splitText();
|
|
176
192
|
if (this.prop.appendLines) {
|
|
177
|
-
this.addViewportCallback(
|
|
193
|
+
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
178
194
|
this.splitText();
|
|
195
|
+
}, {
|
|
196
|
+
timeout: this.prop.resizeTimeout,
|
|
179
197
|
});
|
|
180
198
|
}
|
|
181
199
|
}
|
|
@@ -228,6 +246,7 @@ export class SplitText <
|
|
|
228
246
|
// get type of the char
|
|
229
247
|
const charCode = char.charCodeAt(0);
|
|
230
248
|
const isWhitespace = charCode === 32 || charCode === 160;
|
|
249
|
+
const isSeparator = [45, 8208, 8211, 8212, 8722].includes(charCode);
|
|
231
250
|
const isNewLine = charCode === 10;
|
|
232
251
|
|
|
233
252
|
// add elements
|
|
@@ -251,6 +270,37 @@ export class SplitText <
|
|
|
251
270
|
if (!this.prop.appendLetters) {
|
|
252
271
|
currentWord.el.innerHTML = currentWord.content;
|
|
253
272
|
}
|
|
273
|
+
|
|
274
|
+
// go to next word if needed
|
|
275
|
+
if (isSeparator) {
|
|
276
|
+
wordIndex += 1;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// only filled words
|
|
281
|
+
this._words = this._words.filter((word, index) => {
|
|
282
|
+
if (word.content.length === 0) {
|
|
283
|
+
if (index > 0) {
|
|
284
|
+
this._words[index - 1].whitespace = word.whitespace;
|
|
285
|
+
this._words[index - 1].br = word.br;
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// post-processing
|
|
293
|
+
let prevWord: NSplitText.Word | undefined;
|
|
294
|
+
this._words.forEach((word) => {
|
|
295
|
+
if (prevWord) {
|
|
296
|
+
if (prevWord.whitespace) {
|
|
297
|
+
word.el.classList.add('pre-whitespace');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (word.whitespace) {
|
|
301
|
+
word.el.classList.add('has-whitespace');
|
|
302
|
+
}
|
|
303
|
+
prevWord = word;
|
|
254
304
|
});
|
|
255
305
|
}
|
|
256
306
|
|
|
@@ -2,8 +2,8 @@ import easingProgress from 'easing-progress';
|
|
|
2
2
|
import { NApplication } from '../../app/Application';
|
|
3
3
|
import { Component, NComponent } from '../../base/Component';
|
|
4
4
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import scoped from '../../utils/math/scoped';
|
|
6
|
+
import clamp from '../../utils/math/clamp';
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -174,8 +174,8 @@ export class StaticTimeline <
|
|
|
174
174
|
for (let index = 0, l = length; index < l; index += 1) {
|
|
175
175
|
const tm = this._nestedTimelines[index];
|
|
176
176
|
// calculate progress of this very timeline
|
|
177
|
-
const tmProgress =
|
|
178
|
-
|
|
177
|
+
const tmProgress = clamp(
|
|
178
|
+
scoped(progressForNested, tm.prop.nestedScope),
|
|
179
179
|
[0, 1],
|
|
180
180
|
);
|
|
181
181
|
tm.progress = tmProgress;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StaticTimeline, NStaticTimeline } from './StaticTimeline';
|
|
2
2
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
3
|
-
import
|
|
3
|
+
import clamp from '../../utils/math/clamp';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -205,7 +205,7 @@ export class Timeline <
|
|
|
205
205
|
|
|
206
206
|
// calculate current progress
|
|
207
207
|
const progressIterator = frameDiff / this.prop.duration / (isReversed ? -1 : 1);
|
|
208
|
-
const progressTarget =
|
|
208
|
+
const progressTarget = clamp(
|
|
209
209
|
this.progress + progressIterator,
|
|
210
210
|
[0, 1],
|
|
211
211
|
);
|
|
@@ -1,64 +1,127 @@
|
|
|
1
|
-
import { addEventListener,
|
|
2
|
-
import { SmoothScroll } from '../../components/scroll/smooth-scroll/SmoothScroll';
|
|
1
|
+
import { addEventListener, selectOne } from 'vevet-dom';
|
|
3
2
|
import { IRemovable } from '../types/general';
|
|
3
|
+
import { SmoothScroll } from '../../components/scroll/smooth-scroll/SmoothScroll';
|
|
4
|
+
import { randID } from '../common';
|
|
5
|
+
|
|
6
|
+
type Container = string | Element | SmoothScroll | Window;
|
|
7
|
+
|
|
8
|
+
interface ArgData {
|
|
9
|
+
scrollTop: number;
|
|
10
|
+
scrollLeft: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Instance {
|
|
14
|
+
id: string;
|
|
15
|
+
container: Container;
|
|
16
|
+
callbacks: {
|
|
17
|
+
id: string;
|
|
18
|
+
callback: (
|
|
19
|
+
data: ArgData,
|
|
20
|
+
) => void;
|
|
21
|
+
}[];
|
|
22
|
+
isPassive: boolean;
|
|
23
|
+
listeners: IRemovable[];
|
|
24
|
+
}
|
|
4
25
|
|
|
5
26
|
interface Props {
|
|
6
|
-
|
|
27
|
+
container: Container;
|
|
28
|
+
callback: (data: ArgData) => void;
|
|
29
|
+
isPassive?: boolean;
|
|
7
30
|
}
|
|
8
31
|
|
|
32
|
+
let instances: Instance[] = [];
|
|
33
|
+
|
|
9
34
|
/**
|
|
10
35
|
* Add OnScroll event
|
|
11
36
|
*/
|
|
12
|
-
export default function onScroll (
|
|
13
|
-
|
|
14
|
-
callback
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
export default function onScroll ({
|
|
38
|
+
container,
|
|
39
|
+
callback,
|
|
40
|
+
isPassive = false,
|
|
41
|
+
}: Props): IRemovable {
|
|
42
|
+
// check if listeners for this element already exist
|
|
43
|
+
let instance = instances.find((data) => (
|
|
44
|
+
data.container === container && data.isPassive === isPassive
|
|
45
|
+
))!;
|
|
46
|
+
const callbackId = randID('scroll-event');
|
|
21
47
|
|
|
22
|
-
if
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
48
|
+
// if a listener exists, we just add a new callback to its stack
|
|
49
|
+
if (instance) {
|
|
50
|
+
instance.callbacks.push({
|
|
51
|
+
id: callbackId,
|
|
52
|
+
callback,
|
|
28
53
|
});
|
|
29
54
|
} else {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
55
|
+
// otherwise we create a new instance
|
|
56
|
+
instance = {
|
|
57
|
+
id: randID('scroll-event-instance'),
|
|
58
|
+
container,
|
|
59
|
+
callbacks: [{
|
|
60
|
+
id: callbackId,
|
|
61
|
+
callback,
|
|
62
|
+
}],
|
|
63
|
+
isPassive,
|
|
64
|
+
listeners: [],
|
|
65
|
+
};
|
|
66
|
+
instances.push(instance);
|
|
67
|
+
|
|
68
|
+
// vars
|
|
69
|
+
const { listeners } = instance;
|
|
70
|
+
|
|
71
|
+
// smooth scroll events
|
|
72
|
+
if (container instanceof SmoothScroll) {
|
|
73
|
+
listeners.push(
|
|
74
|
+
container.addCallback('scroll', () => {
|
|
75
|
+
const { scrollTop, scrollLeft } = container;
|
|
76
|
+
for (let index = 0; index < instance.callbacks.length; index += 1) {
|
|
77
|
+
instance.callbacks[index].callback({
|
|
78
|
+
scrollTop,
|
|
79
|
+
scrollLeft,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
33
84
|
} else {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
85
|
+
// dom scroll events
|
|
86
|
+
const isWindow = container instanceof Window;
|
|
87
|
+
const domContainer = selectOne(container) as any;
|
|
37
88
|
listeners.push(addEventListener(
|
|
38
|
-
|
|
89
|
+
domContainer,
|
|
39
90
|
'scroll',
|
|
40
91
|
() => {
|
|
41
|
-
const scrollTop =
|
|
42
|
-
?
|
|
43
|
-
const scrollLeft =
|
|
44
|
-
?
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
92
|
+
const scrollTop = isWindow
|
|
93
|
+
? domContainer.pageYOffset : domContainer.scrollTop;
|
|
94
|
+
const scrollLeft = isWindow
|
|
95
|
+
? domContainer.pageXOffset : domContainer.scrollLeft;
|
|
96
|
+
for (let index = 0; index < instance.callbacks.length; index += 1) {
|
|
97
|
+
instance.callbacks[index].callback({
|
|
98
|
+
scrollTop,
|
|
99
|
+
scrollLeft,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
passive: isPassive,
|
|
49
105
|
},
|
|
50
|
-
props ? {
|
|
51
|
-
passive: props.passive,
|
|
52
|
-
} : undefined,
|
|
53
106
|
));
|
|
54
107
|
}
|
|
55
108
|
}
|
|
56
109
|
|
|
57
110
|
return {
|
|
58
111
|
remove: () => {
|
|
59
|
-
|
|
60
|
-
|
|
112
|
+
const newCallbacks = instance.callbacks.filter((item) => {
|
|
113
|
+
if (item.id !== callbackId) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
61
117
|
});
|
|
118
|
+
instance.callbacks = newCallbacks;
|
|
119
|
+
if (newCallbacks.length === 0) {
|
|
120
|
+
instance.listeners.forEach((listener) => {
|
|
121
|
+
listener.remove();
|
|
122
|
+
});
|
|
123
|
+
instances = instances.filter((item) => item.id !== instance.id);
|
|
124
|
+
}
|
|
62
125
|
},
|
|
63
126
|
};
|
|
64
127
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Clamp the value between two points
|
|
3
3
|
*/
|
|
4
|
-
export default function
|
|
4
|
+
export default function clamp (
|
|
5
5
|
val: number,
|
|
6
|
-
scope
|
|
6
|
+
scope = [0, 1],
|
|
7
7
|
) {
|
|
8
8
|
if (val < scope[0]) {
|
|
9
9
|
return scope[0];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import scoped from './scoped';
|
|
2
|
+
import clamp from './clamp';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get progress relatively to the scope and clamp it within two points
|
|
6
|
+
*/
|
|
7
|
+
export default function clampScoped (
|
|
8
|
+
val: number,
|
|
9
|
+
scope = [0, 1],
|
|
10
|
+
clampScope = [0, 1],
|
|
11
|
+
) {
|
|
12
|
+
return clamp(
|
|
13
|
+
scoped(val, scope),
|
|
14
|
+
clampScope,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import clamp from './clamp';
|
|
2
2
|
import lerp from './lerp';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import scoped from './scoped';
|
|
4
|
+
import spreadScope from './spreadScope';
|
|
5
|
+
import inScope from './inScope';
|
|
6
|
+
import clampScope from './clampScope';
|
|
7
|
+
import wrap from './wrap';
|
|
5
8
|
|
|
6
9
|
export {
|
|
7
|
-
|
|
10
|
+
clamp,
|
|
8
11
|
lerp,
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
scoped,
|
|
13
|
+
spreadScope,
|
|
14
|
+
inScope,
|
|
15
|
+
clampScope,
|
|
16
|
+
wrap,
|
|
11
17
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get progress relatively to the scope.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* scope(.35, [0, 1]);
|
|
7
|
+
* // => .5
|
|
8
|
+
* scope(.35, [.25, 1]);
|
|
9
|
+
* // => .133
|
|
10
|
+
*/
|
|
11
|
+
export default function scoped (
|
|
12
|
+
val: number,
|
|
13
|
+
scopeValue = [0, 1],
|
|
14
|
+
) {
|
|
15
|
+
const result = (val - scopeValue[0]) / (scopeValue[1] - scopeValue[0]);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Distribute scope progress among a certain quantity of timelines.
|
|
3
3
|
*/
|
|
4
|
-
export default function
|
|
4
|
+
export default function spreadScope (
|
|
5
5
|
quantity: number,
|
|
6
6
|
shift: number,
|
|
7
7
|
) {
|
|
8
|
-
const timelines: [
|
|
8
|
+
const timelines: number[][] = [];
|
|
9
9
|
// duration for each element
|
|
10
10
|
const duration = 1 / (quantity - shift * (quantity - 1));
|
|
11
11
|
// calculate timelines
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap values
|
|
3
|
+
*/
|
|
4
|
+
export default function wrap (
|
|
5
|
+
min: number,
|
|
6
|
+
max: number,
|
|
7
|
+
value: number,
|
|
8
|
+
) {
|
|
9
|
+
const range = max - min;
|
|
10
|
+
return conditionalReturn(value, (val) => ((range + ((val - min) % range)) % range) + min);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function conditionalReturn (
|
|
14
|
+
value: number,
|
|
15
|
+
func: (val: number) => number,
|
|
16
|
+
) {
|
|
17
|
+
return value || value === 0 ? func(value) : func;
|
|
18
|
+
}
|