vevet 2.0.1-dev.5 → 2.0.2
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 +8 -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 +34 -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 +65 -25
- 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 -5
- package/build/cjs/utils/math/scoped.js +18 -0
- package/build/cjs/utils/math/spreadScope.js +18 -0
- package/build/cjs/utils/math/wrap.js +13 -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 +25 -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 +64 -25
- 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 -3
- package/build/es/utils/math/scoped.js +14 -0
- package/build/es/utils/math/spreadScope.js +15 -0
- package/build/es/utils/math/wrap.js +10 -0
- 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 +13 -5
- 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 -3
- 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/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 +38 -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 +105 -34
- 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 -4
- package/src/ts/utils/math/scoped.ts +17 -0
- package/src/ts/utils/math/spreadScope.ts +18 -0
- 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/src/ts/utils/math/scopeProgress.ts +0 -23
|
@@ -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,46 +1,107 @@
|
|
|
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
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
container: Container;
|
|
28
|
+
callback: (data: ArgData) => void;
|
|
29
|
+
isPassive?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let instances: Instance[] = [];
|
|
4
33
|
|
|
5
34
|
/**
|
|
6
35
|
* Add OnScroll event
|
|
7
36
|
*/
|
|
8
|
-
export default function onScroll (
|
|
9
|
-
|
|
10
|
-
callback
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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');
|
|
47
|
+
|
|
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,
|
|
23
53
|
});
|
|
24
54
|
} else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
);
|
|
28
84
|
} else {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
85
|
+
// dom scroll events
|
|
86
|
+
const isWindow = container instanceof Window;
|
|
87
|
+
const domContainer = selectOne(container) as any;
|
|
32
88
|
listeners.push(addEventListener(
|
|
33
|
-
|
|
89
|
+
domContainer,
|
|
34
90
|
'scroll',
|
|
35
91
|
() => {
|
|
36
|
-
const scrollTop =
|
|
37
|
-
?
|
|
38
|
-
const scrollLeft =
|
|
39
|
-
?
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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,
|
|
44
105
|
},
|
|
45
106
|
));
|
|
46
107
|
}
|
|
@@ -48,9 +109,19 @@ export default function onScroll (
|
|
|
48
109
|
|
|
49
110
|
return {
|
|
50
111
|
remove: () => {
|
|
51
|
-
|
|
52
|
-
|
|
112
|
+
const newCallbacks = instance.callbacks.filter((item) => {
|
|
113
|
+
if (item.id !== callbackId) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
53
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
|
+
}
|
|
54
125
|
},
|
|
55
126
|
};
|
|
56
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,9 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import clamp from './clamp';
|
|
2
2
|
import lerp from './lerp';
|
|
3
|
-
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';
|
|
4
8
|
|
|
5
9
|
export {
|
|
6
|
-
|
|
10
|
+
clamp,
|
|
7
11
|
lerp,
|
|
8
|
-
|
|
12
|
+
scoped,
|
|
13
|
+
spreadScope,
|
|
14
|
+
inScope,
|
|
15
|
+
clampScope,
|
|
16
|
+
wrap,
|
|
9
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distribute scope progress among a certain quantity of timelines.
|
|
3
|
+
*/
|
|
4
|
+
export default function spreadScope (
|
|
5
|
+
quantity: number,
|
|
6
|
+
shift: number,
|
|
7
|
+
) {
|
|
8
|
+
const timelines: number[][] = [];
|
|
9
|
+
// duration for each element
|
|
10
|
+
const duration = 1 / (quantity - shift * (quantity - 1));
|
|
11
|
+
// calculate timelines
|
|
12
|
+
for (let index = 0; index < quantity; index += 1) {
|
|
13
|
+
const start = (duration * (1 - shift)) * index;
|
|
14
|
+
const end = start + duration;
|
|
15
|
+
timelines.push([start, end]);
|
|
16
|
+
}
|
|
17
|
+
return timelines;
|
|
18
|
+
}
|
|
@@ -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
|
+
}
|