vevet 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cdn/index.js +1 -1
- package/build/cjs/components/scroll/scrollable/ScrollView.js +2 -2
- package/build/cjs/components/scroll/section/ScrollSectionProgress.js +261 -0
- package/build/cjs/index.js +3 -1
- package/build/es/components/scroll/scrollable/ScrollView.js +2 -2
- package/build/es/components/scroll/section/ScrollSectionProgress.js +181 -0
- package/build/es/index.js +2 -1
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +6 -0
- package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
- package/build/types/components/scroll/section/ScrollSectionProgress.d.ts +131 -0
- package/build/types/components/scroll/section/ScrollSectionProgress.d.ts.map +1 -0
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ts/components/scroll/scrollable/ScrollView.ts +8 -1
- package/src/ts/components/scroll/section/ScrollSectionProgress.ts +344 -0
- package/src/ts/index.ts +2 -0
|
@@ -71,7 +71,7 @@ var ScrollView = /** @class */ (function (_super) {
|
|
|
71
71
|
configurable: true
|
|
72
72
|
});
|
|
73
73
|
ScrollView.prototype._getDefaultProp = function () {
|
|
74
|
-
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true, resizeTimeout: 0 });
|
|
74
|
+
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true, viewportTarget: '', resizeTimeout: 0 });
|
|
75
75
|
};
|
|
76
76
|
Object.defineProperty(ScrollView.prototype, "elements", {
|
|
77
77
|
/**
|
|
@@ -91,7 +91,7 @@ var ScrollView = /** @class */ (function (_super) {
|
|
|
91
91
|
var _this = this;
|
|
92
92
|
_super.prototype._setEvents.call(this);
|
|
93
93
|
this.resize();
|
|
94
|
-
this.addViewportCallback(
|
|
94
|
+
this.addViewportCallback(this.prop.viewportTarget, function () {
|
|
95
95
|
_this.resize();
|
|
96
96
|
}, {
|
|
97
97
|
timeout: this.prop.resizeTimeout,
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ScrollSectionProgress = void 0;
|
|
33
|
+
var vevet_dom_1 = require("vevet-dom");
|
|
34
|
+
var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
|
|
35
|
+
var Component_1 = require("../../../base/Component");
|
|
36
|
+
var clampScope_1 = __importDefault(require("../../../utils/math/clampScope"));
|
|
37
|
+
var getScrollValues_1 = __importDefault(require("../../../utils/scroll/getScrollValues"));
|
|
38
|
+
/**
|
|
39
|
+
* Elements into viewport
|
|
40
|
+
*/
|
|
41
|
+
var ScrollSectionProgress = /** @class */ (function (_super) {
|
|
42
|
+
__extends(ScrollSectionProgress, _super);
|
|
43
|
+
function ScrollSectionProgress(initialProp, init) {
|
|
44
|
+
if (init === void 0) { init = true; }
|
|
45
|
+
var _this = _super.call(this, initialProp, false) || this;
|
|
46
|
+
// get scroll container
|
|
47
|
+
if (typeof _this.prop.container === 'string') {
|
|
48
|
+
_this._scrollContainer = (0, vevet_dom_1.selectOne)(_this.prop.container);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
_this._scrollContainer = _this.prop.container;
|
|
52
|
+
}
|
|
53
|
+
// get section element
|
|
54
|
+
if (typeof _this.prop.section === 'string') {
|
|
55
|
+
_this._section = (0, vevet_dom_1.selectOne)(_this.prop.section);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
_this._section = _this.prop.section;
|
|
59
|
+
}
|
|
60
|
+
// set defaults
|
|
61
|
+
_this._progress = -0.001;
|
|
62
|
+
_this._scopeScroll = [0, 0];
|
|
63
|
+
_this._scopeIn = [0, 0];
|
|
64
|
+
_this._scopeMove = [0, 0];
|
|
65
|
+
_this._scopeOut = [0, 0];
|
|
66
|
+
// initialize the class
|
|
67
|
+
if (init) {
|
|
68
|
+
_this.init();
|
|
69
|
+
}
|
|
70
|
+
return _this;
|
|
71
|
+
}
|
|
72
|
+
ScrollSectionProgress.prototype._getDefaultProp = function () {
|
|
73
|
+
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, viewportTarget: '', resizeTimeout: 0 });
|
|
74
|
+
};
|
|
75
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "scrollContainer", {
|
|
76
|
+
get: function () {
|
|
77
|
+
return this._scrollContainer;
|
|
78
|
+
},
|
|
79
|
+
enumerable: false,
|
|
80
|
+
configurable: true
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "section", {
|
|
83
|
+
get: function () {
|
|
84
|
+
return this._section;
|
|
85
|
+
},
|
|
86
|
+
enumerable: false,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "scopeScroll", {
|
|
90
|
+
get: function () {
|
|
91
|
+
return this._scopeScroll;
|
|
92
|
+
},
|
|
93
|
+
enumerable: false,
|
|
94
|
+
configurable: true
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "scopeIn", {
|
|
97
|
+
get: function () {
|
|
98
|
+
return this._scopeIn;
|
|
99
|
+
},
|
|
100
|
+
enumerable: false,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "scopeMove", {
|
|
104
|
+
get: function () {
|
|
105
|
+
return this._scopeMove;
|
|
106
|
+
},
|
|
107
|
+
enumerable: false,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "scopeOut", {
|
|
111
|
+
get: function () {
|
|
112
|
+
return this._scopeOut;
|
|
113
|
+
},
|
|
114
|
+
enumerable: false,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "progress", {
|
|
118
|
+
/**
|
|
119
|
+
* Global progress
|
|
120
|
+
*/
|
|
121
|
+
get: function () {
|
|
122
|
+
return this._progress;
|
|
123
|
+
},
|
|
124
|
+
set: function (val) {
|
|
125
|
+
this._progress = val;
|
|
126
|
+
},
|
|
127
|
+
enumerable: false,
|
|
128
|
+
configurable: true
|
|
129
|
+
});
|
|
130
|
+
ScrollSectionProgress.prototype.init = function () {
|
|
131
|
+
_super.prototype.init.call(this);
|
|
132
|
+
};
|
|
133
|
+
// Set Module Events
|
|
134
|
+
ScrollSectionProgress.prototype._setEvents = function () {
|
|
135
|
+
var _this = this;
|
|
136
|
+
_super.prototype._setEvents.call(this);
|
|
137
|
+
// set resize events
|
|
138
|
+
this.addViewportCallback(this.prop.viewportTarget, function () {
|
|
139
|
+
_this.resize();
|
|
140
|
+
}, {
|
|
141
|
+
timeout: this.prop.resizeTimeout,
|
|
142
|
+
});
|
|
143
|
+
// resize on page loaded
|
|
144
|
+
this._loadedEvent = this._app.onPageLoaded();
|
|
145
|
+
this._loadedEvent.then(function () {
|
|
146
|
+
_this.resize();
|
|
147
|
+
}).catch(function () { });
|
|
148
|
+
// set scroll events
|
|
149
|
+
this._scrollEvent = (0, onScroll_1.default)({
|
|
150
|
+
container: this.prop.container,
|
|
151
|
+
callback: this._handleScroll.bind(this),
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
ScrollSectionProgress.prototype._onPropMutate = function () {
|
|
155
|
+
_super.prototype._onPropMutate.call(this);
|
|
156
|
+
this.resize();
|
|
157
|
+
};
|
|
158
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "progressIn", {
|
|
159
|
+
/**
|
|
160
|
+
* 'in' progress
|
|
161
|
+
*/
|
|
162
|
+
get: function () {
|
|
163
|
+
return (0, clampScope_1.default)(this.progress, this.scopeIn) || 0;
|
|
164
|
+
},
|
|
165
|
+
enumerable: false,
|
|
166
|
+
configurable: true
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "progressOut", {
|
|
169
|
+
/**
|
|
170
|
+
* 'out' progress
|
|
171
|
+
*/
|
|
172
|
+
get: function () {
|
|
173
|
+
return (0, clampScope_1.default)(this.progress, this.scopeOut) || 0;
|
|
174
|
+
},
|
|
175
|
+
enumerable: false,
|
|
176
|
+
configurable: true
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(ScrollSectionProgress.prototype, "progressMove", {
|
|
179
|
+
/**
|
|
180
|
+
* 'move' progress
|
|
181
|
+
*/
|
|
182
|
+
get: function () {
|
|
183
|
+
return (0, clampScope_1.default)(this.progress, this.scopeMove) || 0;
|
|
184
|
+
},
|
|
185
|
+
enumerable: false,
|
|
186
|
+
configurable: true
|
|
187
|
+
});
|
|
188
|
+
/**
|
|
189
|
+
* Handle scroll event
|
|
190
|
+
*/
|
|
191
|
+
ScrollSectionProgress.prototype._handleScroll = function () {
|
|
192
|
+
// calculate scopes
|
|
193
|
+
var scrollData = (0, getScrollValues_1.default)(this.scrollContainer);
|
|
194
|
+
if (!scrollData) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this._render(scrollData);
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Resize the scene
|
|
201
|
+
*/
|
|
202
|
+
ScrollSectionProgress.prototype.resize = function () {
|
|
203
|
+
// calculate scopes
|
|
204
|
+
var scrollData = (0, getScrollValues_1.default)(this.scrollContainer);
|
|
205
|
+
if (!scrollData) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// get sizes
|
|
209
|
+
var bounding = this.section.getBoundingClientRect();
|
|
210
|
+
var vHeight = this._app.viewport.height;
|
|
211
|
+
// calculate scroll scope
|
|
212
|
+
var inStart = scrollData.scrollTop + bounding.top - vHeight;
|
|
213
|
+
var moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
|
|
214
|
+
var scrollLine = moveEnd - inStart;
|
|
215
|
+
this._scopeScroll = [inStart, moveEnd];
|
|
216
|
+
// calculate scopes
|
|
217
|
+
this._scopeIn = [0, vHeight / scrollLine];
|
|
218
|
+
this._scopeOut = [1 - vHeight / scrollLine, 1];
|
|
219
|
+
this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
|
|
220
|
+
// launch callbacks
|
|
221
|
+
this.callbacks.tbt('resize', false);
|
|
222
|
+
// render the scene
|
|
223
|
+
this._render(scrollData, true);
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Render the scene
|
|
227
|
+
*/
|
|
228
|
+
ScrollSectionProgress.prototype._render = function (scrollData, force) {
|
|
229
|
+
if (force === void 0) { force = false; }
|
|
230
|
+
var canRender = this._canRender(scrollData, force);
|
|
231
|
+
if (!canRender) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.callbacks.tbt('render', false);
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Check if the section can be rendered
|
|
238
|
+
*/
|
|
239
|
+
ScrollSectionProgress.prototype._canRender = function (scrollData, force) {
|
|
240
|
+
if (force === void 0) { force = false; }
|
|
241
|
+
if (!scrollData) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
var scrollTop = scrollData.scrollTop;
|
|
245
|
+
var prevProgress = this.progress;
|
|
246
|
+
var progress = (0, clampScope_1.default)(scrollTop, [this._scopeScroll[0], this._scopeScroll[1]]) || 0;
|
|
247
|
+
this.progress = progress;
|
|
248
|
+
return force || (progress !== prevProgress);
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Destroy the module
|
|
252
|
+
*/
|
|
253
|
+
ScrollSectionProgress.prototype._destroy = function () {
|
|
254
|
+
var _a, _b;
|
|
255
|
+
_super.prototype._destroy.call(this);
|
|
256
|
+
(_a = this._scrollEvent) === null || _a === void 0 ? void 0 : _a.remove();
|
|
257
|
+
(_b = this._loadedEvent) === null || _b === void 0 ? void 0 : _b.cancel();
|
|
258
|
+
};
|
|
259
|
+
return ScrollSectionProgress;
|
|
260
|
+
}(Component_1.Component));
|
|
261
|
+
exports.ScrollSectionProgress = ScrollSectionProgress;
|
package/build/cjs/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.CustomCursor = exports.SplitText = exports.SmoothScrollDragPlugin = exports.SmoothScrollKeyboardPlugin = exports.ScrollView = exports.ScrollEventsBase = exports.ScrollBar = exports.SmoothScroll = exports.Ctx2DPrerender = exports.Ctx2D = exports.DraggerDirection = exports.DraggerMove = exports.Dragger = exports.ProgressPreloader = exports.Preloader = exports.Timeline = exports.StaticTimeline = exports.AnimationFrame = exports.WheelHandler = exports.Page = exports.Plugin = exports.Component = exports.Module = exports.MutableProp = exports.Callbacks = exports.PageLoad = exports.Viewport = exports.Application = exports.GeneralTypes = exports.utils = void 0;
|
|
22
|
+
exports.CustomCursor = exports.SplitText = exports.ScrollSectionProgress = exports.SmoothScrollDragPlugin = exports.SmoothScrollKeyboardPlugin = exports.ScrollView = exports.ScrollEventsBase = exports.ScrollBar = exports.SmoothScroll = exports.Ctx2DPrerender = exports.Ctx2D = exports.DraggerDirection = exports.DraggerMove = exports.Dragger = exports.ProgressPreloader = exports.Preloader = exports.Timeline = exports.StaticTimeline = exports.AnimationFrame = exports.WheelHandler = exports.Page = exports.Plugin = exports.Component = exports.Module = exports.MutableProp = exports.Callbacks = exports.PageLoad = exports.Viewport = exports.Application = exports.GeneralTypes = exports.utils = void 0;
|
|
23
23
|
var common = __importStar(require("./utils/common"));
|
|
24
24
|
var listeners = __importStar(require("./utils/listeners"));
|
|
25
25
|
var math = __importStar(require("./utils/math"));
|
|
@@ -78,6 +78,8 @@ var SmoothScrollKeyboardPlugin_1 = require("./components/scroll/plugins/SmoothSc
|
|
|
78
78
|
Object.defineProperty(exports, "SmoothScrollKeyboardPlugin", { enumerable: true, get: function () { return SmoothScrollKeyboardPlugin_1.SmoothScrollKeyboardPlugin; } });
|
|
79
79
|
var SmoothScrollDragPlugin_1 = require("./components/scroll/plugins/SmoothScrollDragPlugin");
|
|
80
80
|
Object.defineProperty(exports, "SmoothScrollDragPlugin", { enumerable: true, get: function () { return SmoothScrollDragPlugin_1.SmoothScrollDragPlugin; } });
|
|
81
|
+
var ScrollSectionProgress_1 = require("./components/scroll/section/ScrollSectionProgress");
|
|
82
|
+
Object.defineProperty(exports, "ScrollSectionProgress", { enumerable: true, get: function () { return ScrollSectionProgress_1.ScrollSectionProgress; } });
|
|
81
83
|
var SplitText_1 = require("./components/text/SplitText");
|
|
82
84
|
Object.defineProperty(exports, "SplitText", { enumerable: true, get: function () { return SplitText_1.SplitText; } });
|
|
83
85
|
var CustomCursor_1 = require("./components/cursor/CustomCursor");
|
|
@@ -23,7 +23,7 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
23
23
|
return `${this._app.prefix}scroll-view`;
|
|
24
24
|
}
|
|
25
25
|
_getDefaultProp() {
|
|
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 });
|
|
26
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true, viewportTarget: '', resizeTimeout: 0 });
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Elements to seek
|
|
@@ -38,7 +38,7 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
38
38
|
_setEvents() {
|
|
39
39
|
super._setEvents();
|
|
40
40
|
this.resize();
|
|
41
|
-
this.addViewportCallback(
|
|
41
|
+
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
42
42
|
this.resize();
|
|
43
43
|
}, {
|
|
44
44
|
timeout: this.prop.resizeTimeout,
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { selectOne } from 'vevet-dom';
|
|
2
|
+
import onScroll from '../../../utils/listeners/onScroll';
|
|
3
|
+
import { Component } from '../../../base/Component';
|
|
4
|
+
import clampScope from '../../../utils/math/clampScope';
|
|
5
|
+
import getScrollValues from '../../../utils/scroll/getScrollValues';
|
|
6
|
+
/**
|
|
7
|
+
* Elements into viewport
|
|
8
|
+
*/
|
|
9
|
+
export class ScrollSectionProgress extends Component {
|
|
10
|
+
constructor(initialProp, init = true) {
|
|
11
|
+
super(initialProp, false);
|
|
12
|
+
// get scroll container
|
|
13
|
+
if (typeof this.prop.container === 'string') {
|
|
14
|
+
this._scrollContainer = selectOne(this.prop.container);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this._scrollContainer = this.prop.container;
|
|
18
|
+
}
|
|
19
|
+
// get section element
|
|
20
|
+
if (typeof this.prop.section === 'string') {
|
|
21
|
+
this._section = selectOne(this.prop.section);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this._section = this.prop.section;
|
|
25
|
+
}
|
|
26
|
+
// set defaults
|
|
27
|
+
this._progress = -0.001;
|
|
28
|
+
this._scopeScroll = [0, 0];
|
|
29
|
+
this._scopeIn = [0, 0];
|
|
30
|
+
this._scopeMove = [0, 0];
|
|
31
|
+
this._scopeOut = [0, 0];
|
|
32
|
+
// initialize the class
|
|
33
|
+
if (init) {
|
|
34
|
+
this.init();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
_getDefaultProp() {
|
|
38
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, viewportTarget: '', resizeTimeout: 0 });
|
|
39
|
+
}
|
|
40
|
+
get scrollContainer() {
|
|
41
|
+
return this._scrollContainer;
|
|
42
|
+
}
|
|
43
|
+
get section() {
|
|
44
|
+
return this._section;
|
|
45
|
+
}
|
|
46
|
+
get scopeScroll() {
|
|
47
|
+
return this._scopeScroll;
|
|
48
|
+
}
|
|
49
|
+
get scopeIn() {
|
|
50
|
+
return this._scopeIn;
|
|
51
|
+
}
|
|
52
|
+
get scopeMove() {
|
|
53
|
+
return this._scopeMove;
|
|
54
|
+
}
|
|
55
|
+
get scopeOut() {
|
|
56
|
+
return this._scopeOut;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Global progress
|
|
60
|
+
*/
|
|
61
|
+
get progress() {
|
|
62
|
+
return this._progress;
|
|
63
|
+
}
|
|
64
|
+
set progress(val) {
|
|
65
|
+
this._progress = val;
|
|
66
|
+
}
|
|
67
|
+
init() {
|
|
68
|
+
super.init();
|
|
69
|
+
}
|
|
70
|
+
// Set Module Events
|
|
71
|
+
_setEvents() {
|
|
72
|
+
super._setEvents();
|
|
73
|
+
// set resize events
|
|
74
|
+
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
75
|
+
this.resize();
|
|
76
|
+
}, {
|
|
77
|
+
timeout: this.prop.resizeTimeout,
|
|
78
|
+
});
|
|
79
|
+
// resize on page loaded
|
|
80
|
+
this._loadedEvent = this._app.onPageLoaded();
|
|
81
|
+
this._loadedEvent.then(() => {
|
|
82
|
+
this.resize();
|
|
83
|
+
}).catch(() => { });
|
|
84
|
+
// set scroll events
|
|
85
|
+
this._scrollEvent = onScroll({
|
|
86
|
+
container: this.prop.container,
|
|
87
|
+
callback: this._handleScroll.bind(this),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
_onPropMutate() {
|
|
91
|
+
super._onPropMutate();
|
|
92
|
+
this.resize();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 'in' progress
|
|
96
|
+
*/
|
|
97
|
+
get progressIn() {
|
|
98
|
+
return clampScope(this.progress, this.scopeIn) || 0;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 'out' progress
|
|
102
|
+
*/
|
|
103
|
+
get progressOut() {
|
|
104
|
+
return clampScope(this.progress, this.scopeOut) || 0;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 'move' progress
|
|
108
|
+
*/
|
|
109
|
+
get progressMove() {
|
|
110
|
+
return clampScope(this.progress, this.scopeMove) || 0;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Handle scroll event
|
|
114
|
+
*/
|
|
115
|
+
_handleScroll() {
|
|
116
|
+
// calculate scopes
|
|
117
|
+
const scrollData = getScrollValues(this.scrollContainer);
|
|
118
|
+
if (!scrollData) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this._render(scrollData);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resize the scene
|
|
125
|
+
*/
|
|
126
|
+
resize() {
|
|
127
|
+
// calculate scopes
|
|
128
|
+
const scrollData = getScrollValues(this.scrollContainer);
|
|
129
|
+
if (!scrollData) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// get sizes
|
|
133
|
+
const bounding = this.section.getBoundingClientRect();
|
|
134
|
+
const vHeight = this._app.viewport.height;
|
|
135
|
+
// calculate scroll scope
|
|
136
|
+
const inStart = scrollData.scrollTop + bounding.top - vHeight;
|
|
137
|
+
const moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
|
|
138
|
+
const scrollLine = moveEnd - inStart;
|
|
139
|
+
this._scopeScroll = [inStart, moveEnd];
|
|
140
|
+
// calculate scopes
|
|
141
|
+
this._scopeIn = [0, vHeight / scrollLine];
|
|
142
|
+
this._scopeOut = [1 - vHeight / scrollLine, 1];
|
|
143
|
+
this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
|
|
144
|
+
// launch callbacks
|
|
145
|
+
this.callbacks.tbt('resize', false);
|
|
146
|
+
// render the scene
|
|
147
|
+
this._render(scrollData, true);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Render the scene
|
|
151
|
+
*/
|
|
152
|
+
_render(scrollData, force = false) {
|
|
153
|
+
const canRender = this._canRender(scrollData, force);
|
|
154
|
+
if (!canRender) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.callbacks.tbt('render', false);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check if the section can be rendered
|
|
161
|
+
*/
|
|
162
|
+
_canRender(scrollData, force = false) {
|
|
163
|
+
if (!scrollData) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const { scrollTop } = scrollData;
|
|
167
|
+
const prevProgress = this.progress;
|
|
168
|
+
const progress = clampScope(scrollTop, [this._scopeScroll[0], this._scopeScroll[1]]) || 0;
|
|
169
|
+
this.progress = progress;
|
|
170
|
+
return force || (progress !== prevProgress);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Destroy the module
|
|
174
|
+
*/
|
|
175
|
+
_destroy() {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
super._destroy();
|
|
178
|
+
(_a = this._scrollEvent) === null || _a === void 0 ? void 0 : _a.remove();
|
|
179
|
+
(_b = this._loadedEvent) === null || _b === void 0 ? void 0 : _b.cancel();
|
|
180
|
+
}
|
|
181
|
+
}
|
package/build/es/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import { ScrollEventsBase } from './components/scroll/scrollable/ScrollEventsBas
|
|
|
29
29
|
import { ScrollView } from './components/scroll/scrollable/ScrollView';
|
|
30
30
|
import { SmoothScrollKeyboardPlugin } from './components/scroll/plugins/SmoothScrollKeyboardPlugin';
|
|
31
31
|
import { SmoothScrollDragPlugin } from './components/scroll/plugins/SmoothScrollDragPlugin';
|
|
32
|
+
import { ScrollSectionProgress } from './components/scroll/section/ScrollSectionProgress';
|
|
32
33
|
import { SplitText } from './components/text/SplitText';
|
|
33
34
|
import { CustomCursor } from './components/cursor/CustomCursor';
|
|
34
35
|
const utils = {
|
|
@@ -37,4 +38,4 @@ const utils = {
|
|
|
37
38
|
math,
|
|
38
39
|
scroll,
|
|
39
40
|
};
|
|
40
|
-
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, };
|
|
41
|
+
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, ScrollSectionProgress, SplitText, CustomCursor, };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ScrollEventsBase, NScrollEventsBase } from './ScrollEventsBase';
|
|
2
2
|
import { IRemovable } from '../../../utils/types/general';
|
|
3
3
|
import { RequiredModuleProp } from '../../../utils/types/utility';
|
|
4
|
+
import { NViewport } from '../../../app/events/Viewport';
|
|
4
5
|
export declare namespace NScrollView {
|
|
5
6
|
/**
|
|
6
7
|
* Static properties
|
|
@@ -47,6 +48,11 @@ export declare namespace NScrollView {
|
|
|
47
48
|
* @default true
|
|
48
49
|
*/
|
|
49
50
|
useIntersectionObserver?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Viewport target on resize
|
|
53
|
+
* @default ''
|
|
54
|
+
*/
|
|
55
|
+
viewportTarget?: keyof NViewport.CallbacksTypes;
|
|
50
56
|
/**
|
|
51
57
|
* @default 0
|
|
52
58
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollView.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"ScrollView.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oB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AW,CAAC,EAAE,EAClB,UAAU,EAAE,OAAO,EACnB,KAAK,SAAI;IAgCb;;OAEG;IACH,SAAS,CAAC,sBAAsB;IAchC;;OAEG;IACI,UAAU,CACb,OAAO,EAAE,OAAO,GACjB,UAAU;IAgBb;;OAEG;IACI,aAAa,CAChB,OAAO,EAAE,OAAO;IASpB;;OAEG;IACI,cAAc;IASrB;;OAEG;IACH,SAAS,CAAC,QAAQ;CAIrB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import PCancelable from 'p-cancelable';
|
|
2
|
+
import { IRemovable } from '../../../utils/types/general';
|
|
3
|
+
import { RequiredModuleProp } from '../../../utils/types/utility';
|
|
4
|
+
import { Component, NComponent } from '../../../base/Component';
|
|
5
|
+
import { NViewport } from '../../../app/events/Viewport';
|
|
6
|
+
import { SmoothScroll } from '../smooth-scroll/SmoothScroll';
|
|
7
|
+
import getScrollValues from '../../../utils/scroll/getScrollValues';
|
|
8
|
+
export declare namespace NScrollSectionProgress {
|
|
9
|
+
/**
|
|
10
|
+
* Static properties
|
|
11
|
+
*/
|
|
12
|
+
interface StaticProp extends NComponent.StaticProp {
|
|
13
|
+
/**
|
|
14
|
+
* The scrollable container
|
|
15
|
+
* @default window
|
|
16
|
+
*/
|
|
17
|
+
container?: string | Element | SmoothScroll | Window;
|
|
18
|
+
/**
|
|
19
|
+
* The scrollable element
|
|
20
|
+
*/
|
|
21
|
+
section: string | Element;
|
|
22
|
+
/**
|
|
23
|
+
* Viewport target on resize
|
|
24
|
+
* @default ''
|
|
25
|
+
*/
|
|
26
|
+
viewportTarget?: keyof NViewport.CallbacksTypes;
|
|
27
|
+
/**
|
|
28
|
+
* @default 0
|
|
29
|
+
*/
|
|
30
|
+
resizeTimeout?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Changeable properties
|
|
34
|
+
*/
|
|
35
|
+
interface ChangeableProp extends NComponent.ChangeableProp {
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Available callbacks
|
|
39
|
+
*/
|
|
40
|
+
interface CallbacksTypes extends NComponent.CallbacksTypes {
|
|
41
|
+
'render': false;
|
|
42
|
+
'resize': false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Elements into viewport
|
|
47
|
+
*/
|
|
48
|
+
export declare class ScrollSectionProgress<StaticProp extends NScrollSectionProgress.StaticProp = NScrollSectionProgress.StaticProp, ChangeableProp extends NScrollSectionProgress.ChangeableProp = NScrollSectionProgress.ChangeableProp, CallbacksTypes extends NScrollSectionProgress.CallbacksTypes = NScrollSectionProgress.CallbacksTypes> extends Component<StaticProp, ChangeableProp, CallbacksTypes> {
|
|
49
|
+
protected _getDefaultProp<T extends RequiredModuleProp<StaticProp & ChangeableProp>>(): T;
|
|
50
|
+
/**
|
|
51
|
+
* Scroll container
|
|
52
|
+
*/
|
|
53
|
+
protected _scrollContainer: Element | SmoothScroll | Window;
|
|
54
|
+
get scrollContainer(): Element | Window | SmoothScroll<import("../smooth-scroll/SmoothScroll").NSmoothScroll.StaticProp, import("../smooth-scroll/SmoothScroll").NSmoothScroll.ChangeableProp, import("../smooth-scroll/SmoothScroll").NSmoothScroll.CallbacksTypes>;
|
|
55
|
+
/**
|
|
56
|
+
* Section element
|
|
57
|
+
*/
|
|
58
|
+
protected _section: Element;
|
|
59
|
+
get section(): Element;
|
|
60
|
+
/**
|
|
61
|
+
* Scroll event
|
|
62
|
+
*/
|
|
63
|
+
protected _scrollEvent?: IRemovable;
|
|
64
|
+
/**
|
|
65
|
+
* Loaded event
|
|
66
|
+
*/
|
|
67
|
+
protected _loadedEvent?: PCancelable<any>;
|
|
68
|
+
/**
|
|
69
|
+
* Scrolling scope
|
|
70
|
+
*/
|
|
71
|
+
protected _scopeScroll: [number, number];
|
|
72
|
+
get scopeScroll(): [number, number];
|
|
73
|
+
/**
|
|
74
|
+
* 'In' scope relative to the global progress
|
|
75
|
+
*/
|
|
76
|
+
protected _scopeIn: [number, number];
|
|
77
|
+
protected get scopeIn(): [number, number];
|
|
78
|
+
/**
|
|
79
|
+
* 'Move' scope relative to the global progress
|
|
80
|
+
*/
|
|
81
|
+
protected _scopeMove: [number, number];
|
|
82
|
+
get scopeMove(): [number, number];
|
|
83
|
+
/**
|
|
84
|
+
* 'Move' scope relative to the global progress
|
|
85
|
+
*/
|
|
86
|
+
protected _scopeOut: [number, number];
|
|
87
|
+
get scopeOut(): [number, number];
|
|
88
|
+
protected _progress: number;
|
|
89
|
+
/**
|
|
90
|
+
* Global progress
|
|
91
|
+
*/
|
|
92
|
+
get progress(): number;
|
|
93
|
+
set progress(val: number);
|
|
94
|
+
constructor(initialProp?: (StaticProp & ChangeableProp), init?: boolean);
|
|
95
|
+
init(): void;
|
|
96
|
+
protected _setEvents(): void;
|
|
97
|
+
protected _onPropMutate(): void;
|
|
98
|
+
/**
|
|
99
|
+
* 'in' progress
|
|
100
|
+
*/
|
|
101
|
+
get progressIn(): number;
|
|
102
|
+
/**
|
|
103
|
+
* 'out' progress
|
|
104
|
+
*/
|
|
105
|
+
get progressOut(): number;
|
|
106
|
+
/**
|
|
107
|
+
* 'move' progress
|
|
108
|
+
*/
|
|
109
|
+
get progressMove(): number;
|
|
110
|
+
/**
|
|
111
|
+
* Handle scroll event
|
|
112
|
+
*/
|
|
113
|
+
protected _handleScroll(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Resize the scene
|
|
116
|
+
*/
|
|
117
|
+
resize(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Render the scene
|
|
120
|
+
*/
|
|
121
|
+
protected _render(scrollData: ReturnType<typeof getScrollValues>, force?: boolean): void;
|
|
122
|
+
/**
|
|
123
|
+
* Check if the section can be rendered
|
|
124
|
+
*/
|
|
125
|
+
protected _canRender(scrollData: ReturnType<typeof getScrollValues>, force?: boolean): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Destroy the module
|
|
128
|
+
*/
|
|
129
|
+
protected _destroy(): void;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=ScrollSectionProgress.d.ts.map
|