vevet 2.0.1-dev.9 → 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 +17 -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 +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/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 +16 -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 +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/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/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 +19 -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 +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
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/**
|
|
4
4
|
* Distribute scope progress among a certain quantity of timelines.
|
|
5
5
|
*/
|
|
6
|
-
function
|
|
6
|
+
function spreadScope(quantity, shift) {
|
|
7
7
|
var timelines = [];
|
|
8
8
|
// duration for each element
|
|
9
9
|
var duration = 1 / (quantity - shift * (quantity - 1));
|
|
@@ -15,4 +15,4 @@ function spreadScopeProgress(quantity, shift) {
|
|
|
15
15
|
}
|
|
16
16
|
return timelines;
|
|
17
17
|
}
|
|
18
|
-
exports.default =
|
|
18
|
+
exports.default = spreadScope;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Wrap values
|
|
5
|
+
*/
|
|
6
|
+
function wrap(min, max, value) {
|
|
7
|
+
var range = max - min;
|
|
8
|
+
return conditionalReturn(value, function (val) { return ((range + ((val - min) % range)) % range) + min; });
|
|
9
|
+
}
|
|
10
|
+
exports.default = wrap;
|
|
11
|
+
function conditionalReturn(value, func) {
|
|
12
|
+
return value || value === 0 ? func(value) : func;
|
|
13
|
+
}
|
package/build/es/base/Module.js
CHANGED
|
@@ -170,10 +170,8 @@ export class Module {
|
|
|
170
170
|
* Add a viewport callback that will be removed on class destroy
|
|
171
171
|
* {@see Viewport}
|
|
172
172
|
*/
|
|
173
|
-
addViewportCallback(target, func, data = {
|
|
174
|
-
name: this.constructor.name
|
|
175
|
-
}) {
|
|
176
|
-
const callback = this._app.viewport.add(target, func, data);
|
|
173
|
+
addViewportCallback(target, func, data = {}) {
|
|
174
|
+
const callback = this._app.viewport.add(target, func, Object.assign(Object.assign({}, data), { name: this.constructor.name }));
|
|
177
175
|
this._viewportCallbacks.push(callback);
|
|
178
176
|
return callback;
|
|
179
177
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component } from '../../base/Component';
|
|
2
|
-
import {
|
|
2
|
+
import { clamp } from '../../utils/math';
|
|
3
3
|
/**
|
|
4
4
|
* Launch an animation frame with a certain FPS
|
|
5
5
|
*/
|
|
@@ -126,7 +126,7 @@ export class AnimationFrame extends Component {
|
|
|
126
126
|
this._frameIndex = newFrameIndex;
|
|
127
127
|
// calculate real fps
|
|
128
128
|
const timeDiff = currentTime - this._prevFrameTime;
|
|
129
|
-
const realFPS =
|
|
129
|
+
const realFPS = clamp(timeDiff === 0 ? 1000 / 60 : Math.floor(1000 / timeDiff), [1, Infinity]);
|
|
130
130
|
// launch callbacks
|
|
131
131
|
this.callbacks.tbt('frame', {
|
|
132
132
|
fps: this.prop.fps,
|
|
@@ -20,7 +20,9 @@ export class Ctx2D extends Component {
|
|
|
20
20
|
});
|
|
21
21
|
this._ctx = this._canvas.getContext('2d');
|
|
22
22
|
// and resize it for the first time
|
|
23
|
-
this.
|
|
23
|
+
if (this.prop.initialResize) {
|
|
24
|
+
this.resize();
|
|
25
|
+
}
|
|
24
26
|
// initialize the class
|
|
25
27
|
if (init) {
|
|
26
28
|
this.init();
|
|
@@ -60,7 +62,7 @@ export class Ctx2D extends Component {
|
|
|
60
62
|
return this._dpr;
|
|
61
63
|
}
|
|
62
64
|
_getDefaultProp() {
|
|
63
|
-
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: false, append: true, updateOnResize: false, width: false, height: false, dpr: false });
|
|
65
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: false, append: true, updateOnResize: false, initialResize: true, resizeTimeout: 0, width: false, height: false, dpr: false });
|
|
64
66
|
}
|
|
65
67
|
// Set Module Events
|
|
66
68
|
_setEvents() {
|
|
@@ -69,6 +71,8 @@ export class Ctx2D extends Component {
|
|
|
69
71
|
const viewportTarget = typeof this.prop.updateOnResize === 'boolean' ? '' : this.prop.updateOnResize;
|
|
70
72
|
this.addViewportCallback(viewportTarget, () => {
|
|
71
73
|
this.resize();
|
|
74
|
+
}, {
|
|
75
|
+
timeout: this.prop.resizeTimeout,
|
|
72
76
|
});
|
|
73
77
|
this.resize();
|
|
74
78
|
}
|
|
@@ -24,9 +24,23 @@ export class Ctx2DPrerender extends Ctx2D {
|
|
|
24
24
|
if (!media) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
+
// get source info
|
|
28
|
+
let source;
|
|
29
|
+
let sourceWidth;
|
|
30
|
+
let sourceHeight;
|
|
31
|
+
if (media instanceof Ctx2D) {
|
|
32
|
+
source = media.canvas;
|
|
33
|
+
sourceWidth = media.width;
|
|
34
|
+
sourceHeight = media.height;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
source = media;
|
|
38
|
+
}
|
|
27
39
|
// get media sizes
|
|
28
40
|
const size = getPos({
|
|
29
|
-
source
|
|
41
|
+
source,
|
|
42
|
+
sourceWidth,
|
|
43
|
+
sourceHeight,
|
|
30
44
|
rule: this.prop.posRule,
|
|
31
45
|
scale: 1,
|
|
32
46
|
width: this.width,
|
|
@@ -34,7 +48,7 @@ export class Ctx2DPrerender extends Ctx2D {
|
|
|
34
48
|
});
|
|
35
49
|
this._ctx.clearRect(0, 0, this.width, this.height);
|
|
36
50
|
// render the media
|
|
37
|
-
this._ctx.drawImage(
|
|
51
|
+
this._ctx.drawImage(source, size.x, size.y, size.width, size.height);
|
|
38
52
|
// launch callbacks on prerender
|
|
39
53
|
this.callbacks.tbt('prerender', false);
|
|
40
54
|
}
|
|
@@ -27,6 +27,7 @@ export class ProgressPreloader extends Preloader {
|
|
|
27
27
|
img: true,
|
|
28
28
|
video: true,
|
|
29
29
|
custom: '.js-preload',
|
|
30
|
+
ignoreClassName: 'js-preload-ignore',
|
|
30
31
|
}, calc: {
|
|
31
32
|
lerp: 0.1,
|
|
32
33
|
forceEnd: 500,
|
|
@@ -126,6 +127,9 @@ export class ProgressPreloader extends Preloader {
|
|
|
126
127
|
if (loaders.img) {
|
|
127
128
|
const imgs = selectAll('img');
|
|
128
129
|
imgs.forEach((img) => {
|
|
130
|
+
if (img.classList.contains(loaders.ignoreClassName)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
129
133
|
this._imgs.push(img);
|
|
130
134
|
this._resourcesTotal += 1;
|
|
131
135
|
});
|
|
@@ -134,13 +138,21 @@ export class ProgressPreloader extends Preloader {
|
|
|
134
138
|
if (loaders.video) {
|
|
135
139
|
const videos = selectAll('video');
|
|
136
140
|
videos.forEach((video) => {
|
|
141
|
+
if (video.classList.contains(loaders.ignoreClassName)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
137
144
|
this._videos.push(video);
|
|
138
145
|
this._resourcesTotal += 1;
|
|
139
146
|
});
|
|
140
147
|
}
|
|
141
148
|
// get custom resources
|
|
142
149
|
if (loaders.custom) {
|
|
143
|
-
this._customResources = Array.from(selectAll(loaders.custom))
|
|
150
|
+
this._customResources = Array.from(selectAll(loaders.custom)).filter((el) => {
|
|
151
|
+
if (el.classList.contains(loaders.ignoreClassName)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
});
|
|
144
156
|
this._resourcesTotal += this._customResources.length;
|
|
145
157
|
}
|
|
146
158
|
}
|
|
@@ -166,7 +178,7 @@ export class ProgressPreloader extends Preloader {
|
|
|
166
178
|
img.addEventListener('error', () => {
|
|
167
179
|
this._handleLoadedResource();
|
|
168
180
|
});
|
|
169
|
-
image.src = img.src;
|
|
181
|
+
image.src = img.currentSrc || img.src;
|
|
170
182
|
}
|
|
171
183
|
});
|
|
172
184
|
// preload videos
|
|
@@ -11,6 +11,7 @@ export class Page extends Component {
|
|
|
11
11
|
constructor(initialProp, init = true) {
|
|
12
12
|
super(initialProp, false);
|
|
13
13
|
// set default vars
|
|
14
|
+
this._blocked = false;
|
|
14
15
|
this._created = false;
|
|
15
16
|
this._shown = false;
|
|
16
17
|
this._hidden = false;
|
|
@@ -21,6 +22,9 @@ export class Page extends Component {
|
|
|
21
22
|
this.init();
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
get blocked() {
|
|
26
|
+
return this._blocked;
|
|
27
|
+
}
|
|
24
28
|
get created() {
|
|
25
29
|
return this._created;
|
|
26
30
|
}
|
|
@@ -46,11 +50,12 @@ export class Page extends Component {
|
|
|
46
50
|
create(viaAJAX = false) {
|
|
47
51
|
return new Promise((resolve, reject) => {
|
|
48
52
|
this.canCreate().then(() => {
|
|
49
|
-
if (this.created) {
|
|
53
|
+
if (this.created || this.blocked) {
|
|
54
|
+
reject();
|
|
50
55
|
return;
|
|
51
56
|
}
|
|
52
57
|
// update vars
|
|
53
|
-
this.
|
|
58
|
+
this._blocked = true;
|
|
54
59
|
this._shown = false;
|
|
55
60
|
this._hidden = false;
|
|
56
61
|
this._destroyed = false;
|
|
@@ -62,7 +67,11 @@ export class Page extends Component {
|
|
|
62
67
|
// actions
|
|
63
68
|
this._create().then(() => {
|
|
64
69
|
this.callbacks.tbt('create', false);
|
|
70
|
+
this._blocked = false;
|
|
71
|
+
this._created = true;
|
|
65
72
|
resolve();
|
|
73
|
+
}).catch(() => {
|
|
74
|
+
reject();
|
|
66
75
|
});
|
|
67
76
|
}).catch(() => {
|
|
68
77
|
reject();
|
|
@@ -95,18 +104,23 @@ export class Page extends Component {
|
|
|
95
104
|
show() {
|
|
96
105
|
return new Promise((resolve, reject) => {
|
|
97
106
|
this.canShow().then(() => {
|
|
98
|
-
if (this.shown) {
|
|
107
|
+
if (this.shown || this.blocked) {
|
|
108
|
+
reject();
|
|
99
109
|
return;
|
|
100
110
|
}
|
|
101
111
|
// update vars
|
|
112
|
+
this._blocked = true;
|
|
102
113
|
this._created = true;
|
|
103
|
-
this._shown = true;
|
|
104
114
|
this._hidden = false;
|
|
105
115
|
this._destroyed = false;
|
|
106
116
|
// actions
|
|
107
117
|
this._show().then(() => {
|
|
108
118
|
this.callbacks.tbt('show', false);
|
|
119
|
+
this._blocked = false;
|
|
120
|
+
this._shown = true;
|
|
109
121
|
resolve();
|
|
122
|
+
}).catch(() => {
|
|
123
|
+
reject();
|
|
110
124
|
});
|
|
111
125
|
// launch events
|
|
112
126
|
}).catch(() => {
|
|
@@ -140,18 +154,23 @@ export class Page extends Component {
|
|
|
140
154
|
hide() {
|
|
141
155
|
return new Promise((resolve, reject) => {
|
|
142
156
|
this.canHide().then(() => {
|
|
143
|
-
if (this.hidden) {
|
|
157
|
+
if (this.hidden || this.blocked) {
|
|
158
|
+
reject();
|
|
144
159
|
return;
|
|
145
160
|
}
|
|
146
161
|
// update vars
|
|
162
|
+
this._blocked = true;
|
|
147
163
|
this._created = true;
|
|
148
164
|
this._shown = false;
|
|
149
|
-
this._hidden = true;
|
|
150
165
|
this._destroyed = false;
|
|
151
166
|
// actions
|
|
152
167
|
this._hide().then(() => {
|
|
153
168
|
this.callbacks.tbt('hide', false);
|
|
169
|
+
this._blocked = false;
|
|
170
|
+
this._hidden = true;
|
|
154
171
|
resolve();
|
|
172
|
+
}).catch(() => {
|
|
173
|
+
reject();
|
|
155
174
|
});
|
|
156
175
|
}).catch(() => {
|
|
157
176
|
reject();
|
|
@@ -184,21 +203,26 @@ export class Page extends Component {
|
|
|
184
203
|
destroy() {
|
|
185
204
|
return new Promise((resolve, reject) => {
|
|
186
205
|
this.canDestroy().then(() => {
|
|
187
|
-
if (this.destroyed) {
|
|
206
|
+
if (this.destroyed || this.blocked) {
|
|
207
|
+
reject();
|
|
188
208
|
return;
|
|
189
209
|
}
|
|
190
210
|
// change vars
|
|
211
|
+
this._blocked = true;
|
|
191
212
|
this._created = false;
|
|
192
213
|
this._shown = false;
|
|
193
214
|
this._hidden = true;
|
|
194
|
-
this._destroyed = true;
|
|
195
215
|
// update page
|
|
196
216
|
this._app.page = false;
|
|
197
217
|
// remove page class
|
|
198
218
|
this._app.html.classList.remove(this.pageClassName);
|
|
199
219
|
// actions
|
|
200
220
|
this._destroy().then(() => {
|
|
221
|
+
this._blocked = false;
|
|
222
|
+
this._destroyed = true;
|
|
201
223
|
resolve();
|
|
224
|
+
}).catch(() => {
|
|
225
|
+
reject();
|
|
202
226
|
});
|
|
203
227
|
}).catch(() => {
|
|
204
228
|
reject();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { selectAll } from 'vevet-dom';
|
|
2
1
|
import { ScrollEventsBase } from './ScrollEventsBase';
|
|
3
2
|
import onScroll from '../../../utils/listeners/onScroll';
|
|
4
3
|
import { intersectionObserverSupported } from '../../../utils/listeners';
|
|
5
|
-
import
|
|
4
|
+
import clamp from '../../../utils/math/clamp';
|
|
6
5
|
import timeoutCallback from '../../../utils/common/timeoutCallback';
|
|
7
6
|
/**
|
|
8
7
|
* Elements into viewport
|
|
@@ -11,10 +10,10 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
11
10
|
constructor(initialProp, init = true) {
|
|
12
11
|
super(initialProp, false);
|
|
13
12
|
this._scrollEvent = undefined;
|
|
14
|
-
this.
|
|
13
|
+
this._intersectionObserverIn = undefined;
|
|
14
|
+
this._intersectionObserverOut = undefined;
|
|
15
15
|
this._firstStart = true;
|
|
16
|
-
|
|
17
|
-
this.updateElements();
|
|
16
|
+
this._elements = [...this.prop.elements];
|
|
18
17
|
// initialize the class
|
|
19
18
|
if (init) {
|
|
20
19
|
this.init();
|
|
@@ -24,11 +23,16 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
24
23
|
return `${this._app.prefix}scroll-view`;
|
|
25
24
|
}
|
|
26
25
|
_getDefaultProp() {
|
|
27
|
-
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, elements:
|
|
26
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true, resizeTimeout: 0 });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Elements to seek
|
|
30
|
+
*/
|
|
31
|
+
get elements() {
|
|
32
|
+
return this._elements;
|
|
28
33
|
}
|
|
29
34
|
init() {
|
|
30
35
|
super.init();
|
|
31
|
-
this.seekBounding();
|
|
32
36
|
}
|
|
33
37
|
// Set Module Events
|
|
34
38
|
_setEvents() {
|
|
@@ -36,20 +40,23 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
36
40
|
this.resize();
|
|
37
41
|
this.addViewportCallback('', () => {
|
|
38
42
|
this.resize();
|
|
43
|
+
}, {
|
|
44
|
+
timeout: this.prop.resizeTimeout,
|
|
39
45
|
});
|
|
40
46
|
}
|
|
41
47
|
_onPropMutate() {
|
|
42
48
|
super._onPropMutate();
|
|
43
|
-
this.
|
|
44
|
-
this.updateElements();
|
|
45
|
-
this._setViewEvents();
|
|
49
|
+
this.resize();
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* Resize the scene
|
|
49
53
|
*/
|
|
50
54
|
resize() {
|
|
51
55
|
this._removeViewEvents();
|
|
52
|
-
this.
|
|
56
|
+
if (this.prop.enabled) {
|
|
57
|
+
this._setViewEvents();
|
|
58
|
+
this.seekBounding();
|
|
59
|
+
}
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
62
|
* Set View events: scroll or intersection
|
|
@@ -63,73 +70,56 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
63
70
|
? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
|
|
64
71
|
const yMargin = this._firstStart
|
|
65
72
|
? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
|
|
66
|
-
// create intersection
|
|
67
|
-
this.
|
|
73
|
+
// create intersection observers
|
|
74
|
+
this._intersectionObserverIn = new IntersectionObserver(this._handleIntersectionObserverIn.bind(this), {
|
|
68
75
|
root: this.intersectionRoot,
|
|
69
76
|
threshold: 0,
|
|
70
77
|
rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
|
|
71
78
|
});
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
this.elements.forEach((el) => {
|
|
80
|
+
var _a;
|
|
81
|
+
(_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(el);
|
|
82
|
+
});
|
|
83
|
+
if (this.prop.states === 'inout') {
|
|
84
|
+
this._intersectionObserverOut = new IntersectionObserver(this._handleIntersectionObserverOut.bind(this), {
|
|
85
|
+
root: this.intersectionRoot,
|
|
86
|
+
threshold: 0,
|
|
87
|
+
rootMargin: '0px 0px 0px 0px',
|
|
88
|
+
});
|
|
74
89
|
this.elements.forEach((el) => {
|
|
75
90
|
var _a;
|
|
76
|
-
(_a = this.
|
|
91
|
+
(_a = this._intersectionObserverOut) === null || _a === void 0 ? void 0 : _a.observe(el);
|
|
77
92
|
});
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
else {
|
|
81
96
|
// set scroll bounding events
|
|
82
|
-
this._scrollEvent = onScroll(
|
|
97
|
+
this._scrollEvent = onScroll({
|
|
98
|
+
container: this.prop.container,
|
|
99
|
+
callback: this._handleScroll.bind(this),
|
|
100
|
+
});
|
|
83
101
|
}
|
|
84
102
|
}
|
|
85
103
|
/**
|
|
86
104
|
* Remove View events: scroll or intersection
|
|
87
105
|
*/
|
|
88
106
|
_removeViewEvents() {
|
|
107
|
+
var _a, _b;
|
|
89
108
|
// remove scroll events
|
|
90
109
|
if (this._scrollEvent) {
|
|
91
110
|
this._scrollEvent.remove();
|
|
92
111
|
this._scrollEvent = undefined;
|
|
93
112
|
}
|
|
94
|
-
// destroy intersection
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Element to seek
|
|
102
|
-
*/
|
|
103
|
-
get elements() {
|
|
104
|
-
return this._elements;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Update elements
|
|
108
|
-
*/
|
|
109
|
-
updateElements() {
|
|
110
|
-
// check if elements exist
|
|
111
|
-
if (typeof this.elements === 'undefined') {
|
|
112
|
-
this._elements = [];
|
|
113
|
-
}
|
|
114
|
-
// unobserve old elements
|
|
115
|
-
this.elements.forEach((el) => {
|
|
116
|
-
if (this._intersectionObserver) {
|
|
117
|
-
this._intersectionObserver.unobserve(el);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
// update elements
|
|
121
|
-
this._elements = Array.from(selectAll(this.prop.elements, this.domParent || undefined)).filter((el) => !el.classList.contains(this.prop.classToToggle));
|
|
122
|
-
// add them to the observer
|
|
123
|
-
this._elements.forEach((el) => {
|
|
124
|
-
if (this._intersectionObserver) {
|
|
125
|
-
this._intersectionObserver.observe(el);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
113
|
+
// destroy intersection observers
|
|
114
|
+
(_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
115
|
+
this._intersectionObserverIn = undefined;
|
|
116
|
+
(_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
117
|
+
this._intersectionObserverOut = undefined;
|
|
128
118
|
}
|
|
129
119
|
/**
|
|
130
120
|
* Event on IntersectionObserver
|
|
131
121
|
*/
|
|
132
|
-
|
|
122
|
+
_handleIntersectionObserverIn(data) {
|
|
133
123
|
const parentBounding = this._firstStart ? this.scrollContainerBounding : false;
|
|
134
124
|
for (let index = 0; index < data.length; index += 1) {
|
|
135
125
|
const entry = data[index];
|
|
@@ -137,7 +127,9 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
137
127
|
if (this._firstStart && !!parentBounding && entry.isIntersecting) {
|
|
138
128
|
delay = this._elementInViewportData(entry.target, parentBounding).delay;
|
|
139
129
|
}
|
|
140
|
-
|
|
130
|
+
if (entry.isIntersecting) {
|
|
131
|
+
this._handleInOut(entry.target, entry.isIntersecting, delay);
|
|
132
|
+
}
|
|
141
133
|
}
|
|
142
134
|
this._processUnusedElements();
|
|
143
135
|
// change states
|
|
@@ -146,6 +138,17 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
146
138
|
this.resize();
|
|
147
139
|
}
|
|
148
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Event on IntersectionObserver
|
|
143
|
+
*/
|
|
144
|
+
_handleIntersectionObserverOut(data) {
|
|
145
|
+
for (let index = 0; index < data.length; index += 1) {
|
|
146
|
+
const entry = data[index];
|
|
147
|
+
if (!entry.isIntersecting) {
|
|
148
|
+
this._handleInOut(entry.target, entry.isIntersecting, 0);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
149
152
|
/**
|
|
150
153
|
* Event on Scroll
|
|
151
154
|
*/
|
|
@@ -168,7 +171,9 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
168
171
|
const el = this.elements[index];
|
|
169
172
|
const elData = this._elementInViewportData(el, scrollContainerBounding);
|
|
170
173
|
const delay = elData.isIntersecting ? elData.delay : 0;
|
|
171
|
-
|
|
174
|
+
if (typeof elData.isIntersecting === 'boolean') {
|
|
175
|
+
this._handleInOut(el, elData.isIntersecting, delay);
|
|
176
|
+
}
|
|
172
177
|
}
|
|
173
178
|
this._processUnusedElements();
|
|
174
179
|
// change states
|
|
@@ -184,7 +189,7 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
184
189
|
const threshold = this._firstStart ? 1 : propThreshold;
|
|
185
190
|
const bounding = el.getBoundingClientRect();
|
|
186
191
|
// check if the element is intersecting
|
|
187
|
-
let isIntersecting
|
|
192
|
+
let isIntersecting;
|
|
188
193
|
if (bounding.top < parentBounding.top + parentBounding.height * threshold
|
|
189
194
|
&& bounding.left < parentBounding.left + parentBounding.width * threshold) {
|
|
190
195
|
if (states === 'in') {
|
|
@@ -198,11 +203,15 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
198
203
|
isIntersecting = true;
|
|
199
204
|
}
|
|
200
205
|
}
|
|
206
|
+
else if (bounding.top > parentBounding.top + parentBounding.height
|
|
207
|
+
|| bounding.left > parentBounding.left + parentBounding.width) {
|
|
208
|
+
isIntersecting = false;
|
|
209
|
+
}
|
|
201
210
|
// calculate delay only if it is enabled & calculations
|
|
202
211
|
// are done for the first time
|
|
203
212
|
let delay = 0;
|
|
204
213
|
if (!!useDelay && this._firstStart) {
|
|
205
|
-
const progress =
|
|
214
|
+
const progress = clamp(useDelay.dir === 'x'
|
|
206
215
|
? (bounding.left - parentBounding.left) / parentBounding.width
|
|
207
216
|
: (bounding.top - parentBounding.top) / parentBounding.height, [0, 1]);
|
|
208
217
|
delay = progress * useDelay.max;
|
|
@@ -225,9 +234,11 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
225
234
|
// update props
|
|
226
235
|
el.scrollViewIn = inViewport;
|
|
227
236
|
// toggle classes
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
237
|
+
if (this.prop.classToToggle) {
|
|
238
|
+
timeoutCallback(() => {
|
|
239
|
+
el.classList.toggle(this.prop.classToToggle, inViewport);
|
|
240
|
+
}, delay);
|
|
241
|
+
}
|
|
231
242
|
// process callbacks
|
|
232
243
|
if (inViewport && (states === 'in' || states === 'inout')) {
|
|
233
244
|
timeoutCallback(() => {
|
|
@@ -250,12 +261,51 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
250
261
|
// remove unused elements
|
|
251
262
|
const elementsToRemove = this._elements.filter((el) => el.scrollViewIn);
|
|
252
263
|
elementsToRemove.forEach((el) => {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
264
|
+
var _a, _b;
|
|
265
|
+
(_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(el);
|
|
266
|
+
(_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(el);
|
|
256
267
|
});
|
|
257
268
|
this._elements = this._elements.filter((el) => !el.scrollViewIn);
|
|
258
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Add a view element
|
|
272
|
+
*/
|
|
273
|
+
addElement(element) {
|
|
274
|
+
var _a, _b;
|
|
275
|
+
const viewEl = element;
|
|
276
|
+
viewEl.scrollViewIn = undefined;
|
|
277
|
+
this._elements.push(element);
|
|
278
|
+
(_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(element);
|
|
279
|
+
(_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.observe(element);
|
|
280
|
+
if (this.prop.enabled) {
|
|
281
|
+
this.seekBounding();
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
remove: () => {
|
|
285
|
+
this.removeElement(element);
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Remove a view element
|
|
291
|
+
*/
|
|
292
|
+
removeElement(element) {
|
|
293
|
+
var _a, _b;
|
|
294
|
+
const viewEl = element;
|
|
295
|
+
viewEl.scrollViewIn = undefined;
|
|
296
|
+
this._elements = this._elements.filter((el) => el !== element);
|
|
297
|
+
(_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(element);
|
|
298
|
+
(_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(element);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Remove all view elements
|
|
302
|
+
*/
|
|
303
|
+
removeElements() {
|
|
304
|
+
this._elements.forEach((el) => {
|
|
305
|
+
this.removeElement(el);
|
|
306
|
+
});
|
|
307
|
+
this._elements = [];
|
|
308
|
+
}
|
|
259
309
|
/**
|
|
260
310
|
* Destroy the module
|
|
261
311
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addEventListener, createElement } from 'vevet-dom';
|
|
2
2
|
import onScroll from '../../../utils/listeners/onScroll';
|
|
3
|
-
import
|
|
3
|
+
import clamp from '../../../utils/math/clamp';
|
|
4
4
|
import { DraggerMove } from '../../dragger/DraggerMove';
|
|
5
5
|
import { SmoothScroll } from '../smooth-scroll/SmoothScroll';
|
|
6
6
|
export default class Bar {
|
|
@@ -106,8 +106,11 @@ export default class Bar {
|
|
|
106
106
|
this._listeners.push(addEventListener(this.outer, 'mouseenter', this._handleHover.bind(this, true)));
|
|
107
107
|
this._listeners.push(addEventListener(this.outer, 'mouseleave', this._handleHover.bind(this, false)));
|
|
108
108
|
// set scroll events
|
|
109
|
-
this._scrollEvent = onScroll(
|
|
110
|
-
this.
|
|
109
|
+
this._scrollEvent = onScroll({
|
|
110
|
+
container: this.prop.container,
|
|
111
|
+
callback: (data) => {
|
|
112
|
+
this._handleScroll(data);
|
|
113
|
+
},
|
|
111
114
|
});
|
|
112
115
|
// set dragger
|
|
113
116
|
if (this.prop.isDraggable) {
|
|
@@ -212,7 +215,7 @@ export default class Bar {
|
|
|
212
215
|
*/
|
|
213
216
|
_renderThumb() {
|
|
214
217
|
// calculate progress
|
|
215
|
-
const progress =
|
|
218
|
+
const progress = clamp(this._scrollVal / this.scrollLine, [0, 1]);
|
|
216
219
|
// calculate transforms
|
|
217
220
|
const x = this.isX ? (this._outerWidth - this._thumbWidth) * progress : 0;
|
|
218
221
|
const y = this.isY ? (this._outerHeight - this._thumbHeight) * progress : 0;
|
|
@@ -231,11 +234,11 @@ export default class Bar {
|
|
|
231
234
|
// calculate thumb sizes
|
|
232
235
|
if (this.prop.autoSize) {
|
|
233
236
|
if (this.isX) {
|
|
234
|
-
const barSize =
|
|
237
|
+
const barSize = clamp(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
|
|
235
238
|
thumb.style.width = `${barSize}px`;
|
|
236
239
|
}
|
|
237
240
|
else {
|
|
238
|
-
const barSize =
|
|
241
|
+
const barSize = clamp(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
|
|
239
242
|
thumb.style.height = `${barSize}px`;
|
|
240
243
|
}
|
|
241
244
|
}
|
|
@@ -56,7 +56,7 @@ export class ScrollBar extends Component {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
_getDefaultProp() {
|
|
59
|
-
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, domParent: false, draggable: true, autoSize: true, autoHide: true, minSize: 50, optimizeCalculations: false, isDraggable: true, draggableScrollBehavior: 'smooth' });
|
|
59
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, domParent: false, draggable: true, autoSize: true, autoHide: true, minSize: 50, optimizeCalculations: false, resizeTimeout: 0, isDraggable: true, draggableScrollBehavior: 'smooth' });
|
|
60
60
|
}
|
|
61
61
|
get prefix() {
|
|
62
62
|
return `${this._app.prefix}scrollbar`;
|
|
@@ -115,6 +115,8 @@ export class ScrollBar extends Component {
|
|
|
115
115
|
else {
|
|
116
116
|
this.addViewportCallback('', () => {
|
|
117
117
|
this.resize();
|
|
118
|
+
}, {
|
|
119
|
+
timeout: this.prop.resizeTimeout,
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
122
|
this.resize();
|