vevet 2.0.1-dev.2 → 2.0.1-dev.23
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/components/canvas/Ctx2DPrerender.js +20 -2
- package/build/cjs/components/loading/ProgressPreloader.js +14 -2
- package/build/cjs/components/page/Page.js +36 -8
- package/build/cjs/components/scroll/plugins/SmoothScrollDragPlugin.js +40 -5
- package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +9 -0
- package/build/cjs/components/scroll/scrollable/ScrollView.js +80 -53
- package/build/cjs/components/scroll/scrollbar/Bar.js +8 -2
- package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +11 -3
- package/build/cjs/components/text/SplitText.js +19 -3
- package/build/cjs/components/timeline/Timeline.js +1 -0
- package/build/cjs/handlers/wheel/WheelHandler.js +195 -0
- package/build/cjs/index.js +3 -1
- package/build/cjs/utils/listeners/onScroll.js +65 -25
- package/build/cjs/utils/math/index.js +5 -1
- package/build/cjs/utils/math/spreadScopeProgress.js +18 -0
- package/build/cjs/utils/math/wrap.js +13 -0
- package/build/es/app/Application.js +50 -93
- package/build/es/app/events/PageLoad.js +3 -7
- package/build/es/app/events/Viewport.js +10 -34
- package/build/es/base/Callbacks.js +8 -19
- package/build/es/base/Component.js +0 -1
- package/build/es/base/Module.js +41 -61
- package/build/es/base/MutableProp.js +10 -32
- package/build/es/base/Plugin.js +0 -1
- package/build/es/components/animation-frame/AnimationFrame.js +4 -28
- package/build/es/components/canvas/Ctx2D.js +21 -49
- package/build/es/components/canvas/Ctx2DPrerender.js +21 -7
- package/build/es/components/cursor/CustomCursor.js +25 -58
- package/build/es/components/dragger/Dragger.js +20 -41
- package/build/es/components/dragger/DraggerDirection.js +1 -4
- package/build/es/components/loading/Preloader.js +26 -41
- package/build/es/components/loading/ProgressPreloader.js +31 -38
- package/build/es/components/page/Page.js +46 -41
- package/build/es/components/scroll/plugins/SmoothScrollDragPlugin.js +47 -29
- package/build/es/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +9 -0
- package/build/es/components/scroll/scrollable/ScrollEventsBase.js +15 -22
- package/build/es/components/scroll/scrollable/ScrollView.js +74 -74
- package/build/es/components/scroll/scrollbar/Bar.js +43 -54
- package/build/es/components/scroll/scrollbar/ScrollBar.js +47 -73
- package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +63 -135
- package/build/es/components/text/SplitText.js +39 -44
- package/build/es/components/timeline/StaticTimeline.js +11 -22
- package/build/es/components/timeline/Timeline.js +13 -28
- package/build/es/handlers/wheel/WheelHandler.js +153 -0
- package/build/es/index.js +2 -1
- package/build/es/utils/listeners/onScroll.js +64 -25
- package/build/es/utils/math/index.js +3 -1
- package/build/es/utils/math/spreadScopeProgress.js +15 -0
- package/build/es/utils/math/wrap.js +10 -0
- 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/plugins/SmoothScrollDragPlugin.d.ts +11 -0
- package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts.map +1 -1
- package/build/types/components/scroll/plugins/SmoothScrollKeyboardPlugin.d.ts.map +1 -1
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +27 -13
- 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/smooth-scroll/SmoothScroll.d.ts.map +1 -1
- package/build/types/components/text/SplitText.d.ts +6 -0
- package/build/types/components/text/SplitText.d.ts.map +1 -1
- package/build/types/components/timeline/Timeline.d.ts.map +1 -1
- package/build/types/handlers/wheel/WheelHandler.d.ts +100 -0
- package/build/types/handlers/wheel/WheelHandler.d.ts.map +1 -0
- package/build/types/index.d.ts +2 -1
- package/build/types/index.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/index.d.ts +3 -1
- package/build/types/utils/math/index.d.ts.map +1 -1
- package/build/types/utils/math/spreadScopeProgress.d.ts +5 -0
- package/build/types/utils/math/spreadScopeProgress.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 +4 -3
- package/src/sass/components/cursor/_custom-cursor.scss +0 -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/plugins/SmoothScrollDragPlugin.ts +58 -5
- package/src/ts/components/scroll/plugins/SmoothScrollKeyboardPlugin.ts +12 -0
- package/src/ts/components/scroll/scrollable/ScrollView.ts +90 -64
- package/src/ts/components/scroll/scrollbar/Bar.ts +8 -2
- package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +12 -3
- package/src/ts/components/text/SplitText.ts +27 -2
- package/src/ts/components/timeline/Timeline.ts +1 -0
- package/src/ts/handlers/wheel/WheelHandler.ts +269 -0
- package/src/ts/index.ts +4 -0
- package/src/ts/utils/listeners/onScroll.ts +105 -34
- package/src/ts/utils/math/index.ts +4 -0
- package/src/ts/utils/math/spreadScopeProgress.ts +18 -0
- package/src/ts/utils/math/wrap.ts +18 -0
|
@@ -8,40 +8,73 @@ import { lerp } from '../../../utils/math';
|
|
|
8
8
|
* Create smooth scrolling.
|
|
9
9
|
*/
|
|
10
10
|
export class SmoothScroll extends Component {
|
|
11
|
+
constructor(initialProp, init = true) {
|
|
12
|
+
super(initialProp, false);
|
|
13
|
+
const { selectors } = this.prop;
|
|
14
|
+
// set default variables
|
|
15
|
+
this._targetLeft = 0;
|
|
16
|
+
this._targetTop = 0;
|
|
17
|
+
this._scrollLeft = 0;
|
|
18
|
+
this._scrollTop = 0;
|
|
19
|
+
this._scrollWidth = 0;
|
|
20
|
+
this._scrollHeight = 0;
|
|
21
|
+
this._clientWidth = 0;
|
|
22
|
+
this._clientHeight = 0;
|
|
23
|
+
this._instant = false;
|
|
24
|
+
this._animationFrame = undefined;
|
|
25
|
+
this._outerAnimationFrameEvent = undefined;
|
|
26
|
+
this._currentFPS = 60;
|
|
27
|
+
// get outer elements
|
|
28
|
+
this._outer = selectOne(selectors.outer);
|
|
29
|
+
if (!(this._outer instanceof HTMLElement)) {
|
|
30
|
+
throw new Error(`${selectors.outer} is not a HTMLElement`);
|
|
31
|
+
}
|
|
32
|
+
this._outer.classList.add(this.prefix);
|
|
33
|
+
// get or create container
|
|
34
|
+
const existingContainer = selectOne(`.${this.prefix}__container`, this.outer);
|
|
35
|
+
if (isElement(existingContainer)) {
|
|
36
|
+
this._container = existingContainer;
|
|
37
|
+
this._containerExists = true;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this._container = createElement('div', {
|
|
41
|
+
class: `${this.prefix}__container`,
|
|
42
|
+
parent: this.outer,
|
|
43
|
+
children: Array.from(this.outer.children),
|
|
44
|
+
});
|
|
45
|
+
this._containerExists = false;
|
|
46
|
+
}
|
|
47
|
+
// get scrollable elements
|
|
48
|
+
if (selectors.elements) {
|
|
49
|
+
this._elements = Array.from(selectAll(selectors.elements, this._outer));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this._elements = [this._container];
|
|
53
|
+
}
|
|
54
|
+
this._elementsLength = this._elements.length;
|
|
55
|
+
// add will-change
|
|
56
|
+
if (this.prop.useWillChange) {
|
|
57
|
+
this._elements.forEach((el) => {
|
|
58
|
+
el.style.willChange = 'transform';
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// initialize the class
|
|
62
|
+
if (init) {
|
|
63
|
+
this.init();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
11
66
|
get prefix() {
|
|
12
67
|
return `${this._app.prefix}smooth-scroll`;
|
|
13
68
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Scroll parent
|
|
16
|
-
*/
|
|
17
|
-
_outer;
|
|
18
69
|
get outer() {
|
|
19
70
|
return this._outer;
|
|
20
71
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Scroll container. If the element does not exist indide the outer,
|
|
23
|
-
* it will be created automatically
|
|
24
|
-
*/
|
|
25
|
-
_container;
|
|
26
72
|
get container() {
|
|
27
73
|
return this._container;
|
|
28
74
|
}
|
|
29
|
-
/**
|
|
30
|
-
* If the container element existed before the class initialization
|
|
31
|
-
*/
|
|
32
|
-
_containerExists;
|
|
33
|
-
/**
|
|
34
|
-
* Scrollable elements
|
|
35
|
-
*/
|
|
36
|
-
_elements;
|
|
37
75
|
get elements() {
|
|
38
76
|
return this._elements;
|
|
39
77
|
}
|
|
40
|
-
_elementsLength;
|
|
41
|
-
/**
|
|
42
|
-
* Scroll target value
|
|
43
|
-
*/
|
|
44
|
-
_targetLeft;
|
|
45
78
|
get targetLeft() {
|
|
46
79
|
return this._targetLeft;
|
|
47
80
|
}
|
|
@@ -62,10 +95,6 @@ export class SmoothScroll extends Component {
|
|
|
62
95
|
get targetLeftBound() {
|
|
63
96
|
return this._targetLeft;
|
|
64
97
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Scroll target value
|
|
67
|
-
*/
|
|
68
|
-
_targetTop;
|
|
69
98
|
get targetTop() {
|
|
70
99
|
return this._targetTop;
|
|
71
100
|
}
|
|
@@ -86,10 +115,6 @@ export class SmoothScroll extends Component {
|
|
|
86
115
|
get targetTopBound() {
|
|
87
116
|
return this._targetTop;
|
|
88
117
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Scroll left
|
|
91
|
-
*/
|
|
92
|
-
_scrollLeft;
|
|
93
118
|
get scrollLeft() {
|
|
94
119
|
return this._scrollLeft;
|
|
95
120
|
}
|
|
@@ -98,10 +123,6 @@ export class SmoothScroll extends Component {
|
|
|
98
123
|
this._scrollLeft = this._targetLeft;
|
|
99
124
|
this._enable();
|
|
100
125
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Scroll top
|
|
103
|
-
*/
|
|
104
|
-
_scrollTop;
|
|
105
126
|
get scrollTop() {
|
|
106
127
|
return this._scrollTop;
|
|
107
128
|
}
|
|
@@ -110,31 +131,15 @@ export class SmoothScroll extends Component {
|
|
|
110
131
|
this._scrollTop = this._targetTop;
|
|
111
132
|
this._enable();
|
|
112
133
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Scroll width
|
|
115
|
-
*/
|
|
116
|
-
_scrollWidth;
|
|
117
134
|
get scrollWidth() {
|
|
118
135
|
return this._scrollWidth;
|
|
119
136
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Scroll height
|
|
122
|
-
*/
|
|
123
|
-
_scrollHeight;
|
|
124
137
|
get scrollHeight() {
|
|
125
138
|
return this._scrollHeight;
|
|
126
139
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Parent width
|
|
129
|
-
*/
|
|
130
|
-
_clientWidth;
|
|
131
140
|
get clientWidth() {
|
|
132
141
|
return this._clientWidth;
|
|
133
142
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Parent height
|
|
136
|
-
*/
|
|
137
|
-
_clientHeight;
|
|
138
143
|
get clientHeight() {
|
|
139
144
|
return this._clientHeight;
|
|
140
145
|
}
|
|
@@ -150,100 +155,19 @@ export class SmoothScroll extends Component {
|
|
|
150
155
|
get maxScrollableHeight() {
|
|
151
156
|
return this.scrollHeight - this.clientHeight;
|
|
152
157
|
}
|
|
153
|
-
/**
|
|
154
|
-
* If the approximation between the target and current scroll values must be instantaneous
|
|
155
|
-
*/
|
|
156
|
-
_instant;
|
|
157
|
-
/**
|
|
158
|
-
* Inner AnimationFrame.
|
|
159
|
-
* The AnimationFrame is not create if an outer AnimationFrame is passed in properties.
|
|
160
|
-
*/
|
|
161
|
-
_animationFrame;
|
|
162
|
-
/**
|
|
163
|
-
* AnimationFrame callback is used for outer AnimationFrame only.
|
|
164
|
-
*/
|
|
165
|
-
_outerAnimationFrameEvent;
|
|
166
|
-
/**
|
|
167
|
-
* Current FPS. Used to normalize LERP ease
|
|
168
|
-
*/
|
|
169
|
-
_currentFPS;
|
|
170
|
-
constructor(initialProp, init = true) {
|
|
171
|
-
super(initialProp, false);
|
|
172
|
-
const { selectors } = this.prop;
|
|
173
|
-
// set default variables
|
|
174
|
-
this._targetLeft = 0;
|
|
175
|
-
this._targetTop = 0;
|
|
176
|
-
this._scrollLeft = 0;
|
|
177
|
-
this._scrollTop = 0;
|
|
178
|
-
this._scrollWidth = 0;
|
|
179
|
-
this._scrollHeight = 0;
|
|
180
|
-
this._clientWidth = 0;
|
|
181
|
-
this._clientHeight = 0;
|
|
182
|
-
this._instant = false;
|
|
183
|
-
this._currentFPS = 60;
|
|
184
|
-
// get outer elements
|
|
185
|
-
this._outer = selectOne(selectors.outer);
|
|
186
|
-
if (!(this._outer instanceof HTMLElement)) {
|
|
187
|
-
throw new Error(`${selectors.outer} is not a HTMLElement`);
|
|
188
|
-
}
|
|
189
|
-
this._outer.classList.add(this.prefix);
|
|
190
|
-
// get or create container
|
|
191
|
-
const existingContainer = selectOne(`.${this.prefix}__container`, this.outer);
|
|
192
|
-
if (isElement(existingContainer)) {
|
|
193
|
-
this._container = existingContainer;
|
|
194
|
-
this._containerExists = true;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
this._container = createElement('div', {
|
|
198
|
-
class: `${this.prefix}__container`,
|
|
199
|
-
parent: this.outer,
|
|
200
|
-
children: Array.from(this.outer.children),
|
|
201
|
-
});
|
|
202
|
-
this._containerExists = false;
|
|
203
|
-
}
|
|
204
|
-
// get scrollable elements
|
|
205
|
-
if (selectors.elements) {
|
|
206
|
-
this._elements = Array.from(selectAll(selectors.elements, this._outer));
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
this._elements = [this._container];
|
|
210
|
-
}
|
|
211
|
-
this._elementsLength = this._elements.length;
|
|
212
|
-
// add will-change
|
|
213
|
-
this._elements.forEach((el) => {
|
|
214
|
-
el.style.willChange = 'transform';
|
|
215
|
-
});
|
|
216
|
-
// initialize the class
|
|
217
|
-
if (init) {
|
|
218
|
-
this.init();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
158
|
_getDefaultProp() {
|
|
222
|
-
return {
|
|
223
|
-
...super._getDefaultProp(),
|
|
224
|
-
selectors: {
|
|
159
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { selectors: {
|
|
225
160
|
outer: `#${this.prefix}`,
|
|
226
161
|
elements: false,
|
|
227
|
-
},
|
|
228
|
-
enabled: true,
|
|
229
|
-
animationFrame: false,
|
|
230
|
-
recalculateSizes: true,
|
|
231
|
-
useWheel: true,
|
|
232
|
-
autoStop: true,
|
|
233
|
-
isHorizontal: false,
|
|
234
|
-
stopPropagation: true,
|
|
235
|
-
useWillChange: true,
|
|
236
|
-
render: {
|
|
162
|
+
}, enabled: true, animationFrame: false, recalculateSizes: true, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
|
|
237
163
|
lerp: 0.1,
|
|
238
164
|
lerpToFixed: 2,
|
|
239
165
|
approximation: 0.1,
|
|
240
166
|
normalizeLerp: false,
|
|
241
|
-
},
|
|
242
|
-
overscroll: {
|
|
167
|
+
}, overscroll: {
|
|
243
168
|
friction: 0.5,
|
|
244
169
|
max: 250,
|
|
245
|
-
}
|
|
246
|
-
};
|
|
170
|
+
} });
|
|
247
171
|
}
|
|
248
172
|
// Extra constructor
|
|
249
173
|
_constructor() {
|
|
@@ -299,6 +223,10 @@ export class SmoothScroll extends Component {
|
|
|
299
223
|
this.targetLeft = parseInt(this.targetLeft.toFixed(0), 10);
|
|
300
224
|
this.targetTop = parseInt(this.targetTop.toFixed(0), 10);
|
|
301
225
|
}
|
|
226
|
+
// set scroll classes
|
|
227
|
+
const hasScroll = this.maxScrollableHeight > 0 || this.maxScrollableWidth > 0;
|
|
228
|
+
outer.classList.toggle('has-scroll', hasScroll);
|
|
229
|
+
outer.classList.toggle('no-scroll', !hasScroll);
|
|
302
230
|
// render elements
|
|
303
231
|
this._updateElementsProp();
|
|
304
232
|
// this.render();
|
|
@@ -4,48 +4,6 @@ import { Component } from '../../base/Component';
|
|
|
4
4
|
* Split text into letters, words & lines
|
|
5
5
|
*/
|
|
6
6
|
export class SplitText extends Component {
|
|
7
|
-
_getDefaultProp() {
|
|
8
|
-
return {
|
|
9
|
-
...super._getDefaultProp(),
|
|
10
|
-
container: `#${this.prefix}`,
|
|
11
|
-
appendLetters: true,
|
|
12
|
-
appendLines: false,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
get prefix() {
|
|
16
|
-
return `${this._app.prefix}split-text`;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Initial text
|
|
20
|
-
*/
|
|
21
|
-
_initText;
|
|
22
|
-
/**
|
|
23
|
-
* Initial HTML content
|
|
24
|
-
*/
|
|
25
|
-
_initHTML;
|
|
26
|
-
/**
|
|
27
|
-
* If the text is already split into letters and words
|
|
28
|
-
*/
|
|
29
|
-
_isPrimarySplit;
|
|
30
|
-
/**
|
|
31
|
-
* Text container
|
|
32
|
-
*/
|
|
33
|
-
get container() {
|
|
34
|
-
return this._container;
|
|
35
|
-
}
|
|
36
|
-
_container;
|
|
37
|
-
get letters() {
|
|
38
|
-
return this._letters;
|
|
39
|
-
}
|
|
40
|
-
_letters;
|
|
41
|
-
get words() {
|
|
42
|
-
return this._words;
|
|
43
|
-
}
|
|
44
|
-
_words;
|
|
45
|
-
get lines() {
|
|
46
|
-
return this._lines;
|
|
47
|
-
}
|
|
48
|
-
_lines;
|
|
49
7
|
constructor(initialProp, init = true) {
|
|
50
8
|
super(initialProp, false);
|
|
51
9
|
// get text container
|
|
@@ -61,7 +19,7 @@ export class SplitText extends Component {
|
|
|
61
19
|
}
|
|
62
20
|
// get initial text
|
|
63
21
|
this._initHTML = this._container.innerHTML;
|
|
64
|
-
this._initText = (this._container.innerText || 'no rendered text').trim();
|
|
22
|
+
this._initText = (this._container.innerText || this._container.innerHTML || 'no rendered text').trim();
|
|
65
23
|
this._initText = this._initText.replace(/\s+\n/gm, '\n');
|
|
66
24
|
// set default vars
|
|
67
25
|
this._isPrimarySplit = false;
|
|
@@ -73,12 +31,33 @@ export class SplitText extends Component {
|
|
|
73
31
|
this.init();
|
|
74
32
|
}
|
|
75
33
|
}
|
|
34
|
+
_getDefaultProp() {
|
|
35
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: `#${this.prefix}`, appendLetters: true, appendLines: false, viewportTarget: '' });
|
|
36
|
+
}
|
|
37
|
+
get prefix() {
|
|
38
|
+
return `${this._app.prefix}split-text`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Text container
|
|
42
|
+
*/
|
|
43
|
+
get container() {
|
|
44
|
+
return this._container;
|
|
45
|
+
}
|
|
46
|
+
get letters() {
|
|
47
|
+
return this._letters;
|
|
48
|
+
}
|
|
49
|
+
get words() {
|
|
50
|
+
return this._words;
|
|
51
|
+
}
|
|
52
|
+
get lines() {
|
|
53
|
+
return this._lines;
|
|
54
|
+
}
|
|
76
55
|
_setEvents() {
|
|
77
56
|
super._setEvents();
|
|
78
57
|
// split the text
|
|
79
58
|
this.splitText();
|
|
80
59
|
if (this.prop.appendLines) {
|
|
81
|
-
this.addViewportCallback(
|
|
60
|
+
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
82
61
|
this.splitText();
|
|
83
62
|
});
|
|
84
63
|
}
|
|
@@ -124,6 +103,7 @@ export class SplitText extends Component {
|
|
|
124
103
|
// get type of the char
|
|
125
104
|
const charCode = char.charCodeAt(0);
|
|
126
105
|
const isWhitespace = charCode === 32 || charCode === 160;
|
|
106
|
+
const isSeparator = [45, 8208, 8211, 8212, 8722].includes(charCode);
|
|
127
107
|
const isNewLine = charCode === 10;
|
|
128
108
|
// add elements
|
|
129
109
|
if (isWhitespace) {
|
|
@@ -144,6 +124,21 @@ export class SplitText extends Component {
|
|
|
144
124
|
if (!this.prop.appendLetters) {
|
|
145
125
|
currentWord.el.innerHTML = currentWord.content;
|
|
146
126
|
}
|
|
127
|
+
// go to next word if needed
|
|
128
|
+
if (isSeparator) {
|
|
129
|
+
wordIndex += 1;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
// only filled words
|
|
133
|
+
this._words = this._words.filter((word, index) => {
|
|
134
|
+
if (word.content.length === 0) {
|
|
135
|
+
if (index > 0) {
|
|
136
|
+
this._words[index - 1].whitespace = word.whitespace;
|
|
137
|
+
this._words[index - 1].br = word.br;
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
147
142
|
});
|
|
148
143
|
}
|
|
149
144
|
/**
|
|
@@ -8,18 +8,22 @@ import boundVal from '../../utils/math/boundVal';
|
|
|
8
8
|
* no play & pause methods.
|
|
9
9
|
*/
|
|
10
10
|
export class StaticTimeline extends Component {
|
|
11
|
+
constructor(initialProp, init = true) {
|
|
12
|
+
super(initialProp, false);
|
|
13
|
+
// set default vars
|
|
14
|
+
this._progress = 0;
|
|
15
|
+
this._easing = 0;
|
|
16
|
+
this._nestedTimelines = [];
|
|
17
|
+
if (init) {
|
|
18
|
+
this.init();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
11
21
|
/**
|
|
12
22
|
* Get default properties
|
|
13
23
|
*/
|
|
14
24
|
_getDefaultProp() {
|
|
15
|
-
return {
|
|
16
|
-
...super._getDefaultProp(),
|
|
17
|
-
easing: this._app.prop.easing,
|
|
18
|
-
scope: [0, 1],
|
|
19
|
-
useNestedEasingProgress: false,
|
|
20
|
-
};
|
|
25
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { easing: this._app.prop.easing, scope: [0, 1], useNestedEasingProgress: false });
|
|
21
26
|
}
|
|
22
|
-
_progress;
|
|
23
27
|
/**
|
|
24
28
|
* Absolute progress of the timeline
|
|
25
29
|
*/
|
|
@@ -30,27 +34,12 @@ export class StaticTimeline extends Component {
|
|
|
30
34
|
this._progress = val;
|
|
31
35
|
this._handleProgress();
|
|
32
36
|
}
|
|
33
|
-
_easing;
|
|
34
37
|
/**
|
|
35
38
|
* Easing progress of the timeline
|
|
36
39
|
*/
|
|
37
40
|
get easing() {
|
|
38
41
|
return this._easing;
|
|
39
42
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Nested timelines
|
|
42
|
-
*/
|
|
43
|
-
_nestedTimelines;
|
|
44
|
-
constructor(initialProp, init = true) {
|
|
45
|
-
super(initialProp, false);
|
|
46
|
-
// set default vars
|
|
47
|
-
this._progress = 0;
|
|
48
|
-
this._easing = 0;
|
|
49
|
-
this._nestedTimelines = [];
|
|
50
|
-
if (init) {
|
|
51
|
-
this.init();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
43
|
/**
|
|
55
44
|
* Add a nested timeline
|
|
56
45
|
*/
|
|
@@ -4,16 +4,23 @@ import boundVal from '../../utils/math/boundVal';
|
|
|
4
4
|
* Timeline is an animation helper.
|
|
5
5
|
*/
|
|
6
6
|
export class Timeline extends StaticTimeline {
|
|
7
|
+
constructor(initialProp, init = true) {
|
|
8
|
+
super(initialProp, false);
|
|
9
|
+
// set default variables
|
|
10
|
+
this._isPlaying = false;
|
|
11
|
+
this._isReversed = false;
|
|
12
|
+
this._isPaused = false;
|
|
13
|
+
this._animationFrame = undefined;
|
|
14
|
+
this._animationFrameLastTime = 0;
|
|
15
|
+
if (init) {
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
/**
|
|
8
20
|
* Get default properties
|
|
9
21
|
*/
|
|
10
22
|
_getDefaultProp() {
|
|
11
|
-
return {
|
|
12
|
-
...super._getDefaultProp(),
|
|
13
|
-
duration: 1000,
|
|
14
|
-
reset: false,
|
|
15
|
-
destroyOnEnd: false,
|
|
16
|
-
};
|
|
23
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { duration: 1000, reset: false, destroyOnEnd: false });
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
19
26
|
* Check if timeline is playing
|
|
@@ -21,40 +28,18 @@ export class Timeline extends StaticTimeline {
|
|
|
21
28
|
get isPlaying() {
|
|
22
29
|
return typeof this._animationFrame !== 'undefined';
|
|
23
30
|
}
|
|
24
|
-
_isPlaying;
|
|
25
31
|
/**
|
|
26
32
|
* Check if timeline is reversed
|
|
27
33
|
*/
|
|
28
34
|
get isReversed() {
|
|
29
35
|
return this._isReversed;
|
|
30
36
|
}
|
|
31
|
-
_isReversed;
|
|
32
37
|
/**
|
|
33
38
|
* Check if timeline is paused
|
|
34
39
|
*/
|
|
35
40
|
get isPaused() {
|
|
36
41
|
return this._isPaused;
|
|
37
42
|
}
|
|
38
|
-
_isPaused;
|
|
39
|
-
/**
|
|
40
|
-
* The animation frame
|
|
41
|
-
*/
|
|
42
|
-
_animationFrame;
|
|
43
|
-
/**
|
|
44
|
-
* Last time when animationFrame callback has been called
|
|
45
|
-
*/
|
|
46
|
-
_animationFrameLastTime;
|
|
47
|
-
constructor(initialProp, init = true) {
|
|
48
|
-
super(initialProp, false);
|
|
49
|
-
// set default variables
|
|
50
|
-
this._isPlaying = false;
|
|
51
|
-
this._isReversed = false;
|
|
52
|
-
this._isPaused = false;
|
|
53
|
-
this._animationFrameLastTime = 0;
|
|
54
|
-
if (init) {
|
|
55
|
-
this.init();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
43
|
/**
|
|
59
44
|
* Play the timeline
|
|
60
45
|
*/
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { addEventListener } from 'vevet-dom';
|
|
2
|
+
import normalizeWheel from 'normalize-wheel';
|
|
3
|
+
import { Module } from '../../base/Module';
|
|
4
|
+
/**
|
|
5
|
+
* Wheel events: up & down, left & right without repeating
|
|
6
|
+
|
|
7
|
+
*/
|
|
8
|
+
export class WheelHandler extends Module {
|
|
9
|
+
constructor(initialProp, init = true) {
|
|
10
|
+
super(initialProp, false);
|
|
11
|
+
this._wheelListener = undefined;
|
|
12
|
+
this._lockWheel = false;
|
|
13
|
+
if (init) {
|
|
14
|
+
this.init();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
_getDefaultProp() {
|
|
18
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: false, enabled: true, stopPropagation: false, threshold: 20 });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Listener contianer
|
|
22
|
+
*/
|
|
23
|
+
get container() {
|
|
24
|
+
if (!this.prop.container) {
|
|
25
|
+
return window;
|
|
26
|
+
}
|
|
27
|
+
return this.prop.container;
|
|
28
|
+
}
|
|
29
|
+
// Set Module Events
|
|
30
|
+
_setEvents() {
|
|
31
|
+
super._setEvents();
|
|
32
|
+
if (!(this.container instanceof Window)) {
|
|
33
|
+
this._listeners.push(addEventListener(this.container, 'mouseenter', this._handleMouseEnter.bind(this)));
|
|
34
|
+
this._listeners.push(addEventListener(this.container, 'mouseleave', this._handleMouseLeave.bind(this)));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this._toggleWheelEvent();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
_onPropMutate() {
|
|
41
|
+
super._onPropMutate();
|
|
42
|
+
this._toggleWheelEvent();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Handle element mouse enter
|
|
46
|
+
*/
|
|
47
|
+
_handleMouseEnter() {
|
|
48
|
+
if (this.prop.enabled) {
|
|
49
|
+
this._createWheelEvent();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Handle element mouse leave
|
|
54
|
+
*/
|
|
55
|
+
_handleMouseLeave() {
|
|
56
|
+
this._destroyWheelEvent();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Set wheel event
|
|
60
|
+
*/
|
|
61
|
+
_toggleWheelEvent() {
|
|
62
|
+
if (this.prop.enabled) {
|
|
63
|
+
this._createWheelEvent();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this._destroyWheelEvent();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a wheel event
|
|
71
|
+
*/
|
|
72
|
+
_createWheelEvent() {
|
|
73
|
+
if (this._wheelListener) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// reset gaining
|
|
77
|
+
this._lockWheel = false;
|
|
78
|
+
if (this._lockWheelTimeout) {
|
|
79
|
+
clearTimeout(this._lockWheelTimeout);
|
|
80
|
+
}
|
|
81
|
+
// create a listener
|
|
82
|
+
this._wheelListener = addEventListener(this.container, 'wheel',
|
|
83
|
+
// throttle(this._handleWheel.bind(this), 200),
|
|
84
|
+
this._handleWheel.bind(this));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Destroy the wheel event
|
|
88
|
+
*/
|
|
89
|
+
_destroyWheelEvent() {
|
|
90
|
+
if (!this._wheelListener) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this._wheelListener.remove();
|
|
94
|
+
this._wheelListener = undefined;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Handle wheel event
|
|
98
|
+
*/
|
|
99
|
+
_handleWheel(evt) {
|
|
100
|
+
if (!this._wheelListener) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// stop propagation
|
|
104
|
+
if (this.prop.stopPropagation) {
|
|
105
|
+
evt.preventDefault();
|
|
106
|
+
evt.stopPropagation();
|
|
107
|
+
}
|
|
108
|
+
// if locked
|
|
109
|
+
if (this._lockWheel) {
|
|
110
|
+
if (this._lockWheelTimeout) {
|
|
111
|
+
clearTimeout(this._lockWheelTimeout);
|
|
112
|
+
}
|
|
113
|
+
this._lockWheelTimeout = setTimeout(() => {
|
|
114
|
+
this._lockWheel = false;
|
|
115
|
+
}, 300);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// data
|
|
119
|
+
const delta = normalizeWheel(evt);
|
|
120
|
+
const { threshold } = this.prop;
|
|
121
|
+
// launch events
|
|
122
|
+
let eventFired = false;
|
|
123
|
+
// Y
|
|
124
|
+
if (delta.pixelY > threshold) {
|
|
125
|
+
this._callbacks.tbt('down', false);
|
|
126
|
+
eventFired = true;
|
|
127
|
+
}
|
|
128
|
+
else if (delta.pixelY < threshold * -1) {
|
|
129
|
+
this._callbacks.tbt('up', false);
|
|
130
|
+
eventFired = true;
|
|
131
|
+
}
|
|
132
|
+
// X
|
|
133
|
+
if (delta.pixelX > threshold) {
|
|
134
|
+
this._callbacks.tbt('right', false);
|
|
135
|
+
eventFired = true;
|
|
136
|
+
}
|
|
137
|
+
else if (delta.pixelX < threshold * -1) {
|
|
138
|
+
this._callbacks.tbt('left', false);
|
|
139
|
+
eventFired = true;
|
|
140
|
+
}
|
|
141
|
+
// lock events
|
|
142
|
+
if (eventFired) {
|
|
143
|
+
this._lockWheel = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Destroy the module
|
|
148
|
+
*/
|
|
149
|
+
_destroy() {
|
|
150
|
+
super._destroy();
|
|
151
|
+
this._destroyWheelEvent();
|
|
152
|
+
}
|
|
153
|
+
}
|
package/build/es/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { Module } from './base/Module';
|
|
|
11
11
|
import { Component } from './base/Component';
|
|
12
12
|
import { Plugin } from './base/Plugin';
|
|
13
13
|
import { Page } from './components/page/Page';
|
|
14
|
+
import { WheelHandler } from './handlers/wheel/WheelHandler';
|
|
14
15
|
import { AnimationFrame } from './components/animation-frame/AnimationFrame';
|
|
15
16
|
import { StaticTimeline } from './components/timeline/StaticTimeline';
|
|
16
17
|
import { Timeline } from './components/timeline/Timeline';
|
|
@@ -34,4 +35,4 @@ const utils = {
|
|
|
34
35
|
listeners,
|
|
35
36
|
math,
|
|
36
37
|
};
|
|
37
|
-
export { utils, GeneralTypes, Application, Viewport, PageLoad, Callbacks, MutableProp, Module, Component, Plugin, Page, AnimationFrame, StaticTimeline, Timeline, Preloader, ProgressPreloader, Dragger, DraggerMove, DraggerDirection, Ctx2D, Ctx2DPrerender, SmoothScroll, ScrollBar, ScrollEventsBase, ScrollView, SmoothScrollKeyboardPlugin, SmoothScrollDragPlugin, SplitText, CustomCursor, };
|
|
38
|
+
export { utils, GeneralTypes, Application, Viewport, PageLoad, Callbacks, MutableProp, Module, Component, Plugin, Page, WheelHandler, AnimationFrame, StaticTimeline, Timeline, Preloader, ProgressPreloader, Dragger, DraggerMove, DraggerDirection, Ctx2D, Ctx2DPrerender, SmoothScroll, ScrollBar, ScrollEventsBase, ScrollView, SmoothScrollKeyboardPlugin, SmoothScrollDragPlugin, SplitText, CustomCursor, };
|