vevet 2.0.1-dev.26 → 2.0.1-dev.30
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/base/Module.js +13 -4
- package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
- package/build/cjs/components/canvas/Ctx2D.js +6 -2
- package/build/cjs/components/scroll/scrollable/ScrollView.js +5 -3
- package/build/cjs/components/scroll/scrollbar/Bar.js +4 -4
- package/build/cjs/components/scroll/scrollbar/ScrollBar.js +3 -1
- package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +8 -6
- package/build/cjs/components/text/SplitText.js +3 -1
- package/build/cjs/components/timeline/StaticTimeline.js +3 -3
- package/build/cjs/components/timeline/Timeline.js +2 -2
- package/build/cjs/utils/math/clamp.js +16 -0
- 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 +11 -7
- package/build/cjs/utils/math/scoped.js +18 -0
- package/build/cjs/utils/math/spreadScope.js +18 -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/scroll/scrollable/ScrollView.js +5 -3
- package/build/es/components/scroll/scrollbar/Bar.js +4 -4
- package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
- package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +8 -6
- package/build/es/components/text/SplitText.js +3 -1
- package/build/es/components/timeline/StaticTimeline.js +3 -3
- package/build/es/components/timeline/Timeline.js +2 -2
- package/build/es/utils/math/clamp.js +12 -0
- 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 +6 -4
- package/build/es/utils/math/scoped.js +14 -0
- package/build/es/utils/math/spreadScope.js +15 -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/scroll/scrollable/ScrollView.d.ts +4 -0
- package/build/types/components/scroll/scrollable/ScrollView.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 +4 -0
- package/build/types/components/text/SplitText.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 +6 -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/package.json +1 -1
- 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/scroll/scrollable/ScrollView.ts +9 -2
- package/src/ts/components/scroll/scrollbar/Bar.ts +4 -4
- package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
- package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +12 -5
- package/src/ts/components/text/SplitText.ts +7 -0
- package/src/ts/components/timeline/StaticTimeline.ts +4 -4
- package/src/ts/components/timeline/Timeline.ts +2 -2
- 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 +10 -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/scopeProgress.ts +0 -23
package/build/cjs/base/Module.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -204,10 +215,8 @@ var Module = /** @class */ (function () {
|
|
|
204
215
|
* {@see Viewport}
|
|
205
216
|
*/
|
|
206
217
|
Module.prototype.addViewportCallback = function (target, func, data) {
|
|
207
|
-
if (data === void 0) { data = {
|
|
208
|
-
|
|
209
|
-
}; }
|
|
210
|
-
var callback = this._app.viewport.add(target, func, data);
|
|
218
|
+
if (data === void 0) { data = {}; }
|
|
219
|
+
var callback = this._app.viewport.add(target, func, __assign(__assign({}, data), { name: this.constructor.name }));
|
|
211
220
|
this._viewportCallbacks.push(callback);
|
|
212
221
|
return callback;
|
|
213
222
|
};
|
|
@@ -162,7 +162,7 @@ var AnimationFrame = /** @class */ (function (_super) {
|
|
|
162
162
|
this._frameIndex = newFrameIndex;
|
|
163
163
|
// calculate real fps
|
|
164
164
|
var timeDiff = currentTime - this._prevFrameTime;
|
|
165
|
-
var realFPS = math_1.
|
|
165
|
+
var realFPS = math_1.clamp(timeDiff === 0 ? 1000 / 60 : Math.floor(1000 / timeDiff), [1, Infinity]);
|
|
166
166
|
// launch callbacks
|
|
167
167
|
this.callbacks.tbt('frame', {
|
|
168
168
|
fps: this.prop.fps,
|
|
@@ -51,7 +51,9 @@ var Ctx2D = /** @class */ (function (_super) {
|
|
|
51
51
|
});
|
|
52
52
|
_this._ctx = _this._canvas.getContext('2d');
|
|
53
53
|
// and resize it for the first time
|
|
54
|
-
_this.
|
|
54
|
+
if (_this.prop.initialResize) {
|
|
55
|
+
_this.resize();
|
|
56
|
+
}
|
|
55
57
|
// initialize the class
|
|
56
58
|
if (init) {
|
|
57
59
|
_this.init();
|
|
@@ -124,7 +126,7 @@ var Ctx2D = /** @class */ (function (_super) {
|
|
|
124
126
|
configurable: true
|
|
125
127
|
});
|
|
126
128
|
Ctx2D.prototype._getDefaultProp = function () {
|
|
127
|
-
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: false, append: true, updateOnResize: false, width: false, height: false, dpr: false });
|
|
129
|
+
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: false, append: true, updateOnResize: false, initialResize: true, resizeTimeout: 0, width: false, height: false, dpr: false });
|
|
128
130
|
};
|
|
129
131
|
// Set Module Events
|
|
130
132
|
Ctx2D.prototype._setEvents = function () {
|
|
@@ -134,6 +136,8 @@ var Ctx2D = /** @class */ (function (_super) {
|
|
|
134
136
|
var viewportTarget = typeof this.prop.updateOnResize === 'boolean' ? '' : this.prop.updateOnResize;
|
|
135
137
|
this.addViewportCallback(viewportTarget, function () {
|
|
136
138
|
_this.resize();
|
|
139
|
+
}, {
|
|
140
|
+
timeout: this.prop.resizeTimeout,
|
|
137
141
|
});
|
|
138
142
|
this.resize();
|
|
139
143
|
}
|
|
@@ -38,7 +38,7 @@ exports.ScrollView = void 0;
|
|
|
38
38
|
var ScrollEventsBase_1 = require("./ScrollEventsBase");
|
|
39
39
|
var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
|
|
40
40
|
var listeners_1 = require("../../../utils/listeners");
|
|
41
|
-
var
|
|
41
|
+
var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
|
|
42
42
|
var timeoutCallback_1 = __importDefault(require("../../../utils/common/timeoutCallback"));
|
|
43
43
|
/**
|
|
44
44
|
* Elements into viewport
|
|
@@ -67,7 +67,7 @@ var ScrollView = /** @class */ (function (_super) {
|
|
|
67
67
|
configurable: true
|
|
68
68
|
});
|
|
69
69
|
ScrollView.prototype._getDefaultProp = function () {
|
|
70
|
-
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
|
|
70
|
+
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 });
|
|
71
71
|
};
|
|
72
72
|
Object.defineProperty(ScrollView.prototype, "elements", {
|
|
73
73
|
/**
|
|
@@ -89,6 +89,8 @@ var ScrollView = /** @class */ (function (_super) {
|
|
|
89
89
|
this.resize();
|
|
90
90
|
this.addViewportCallback('', function () {
|
|
91
91
|
_this.resize();
|
|
92
|
+
}, {
|
|
93
|
+
timeout: this.prop.resizeTimeout,
|
|
92
94
|
});
|
|
93
95
|
};
|
|
94
96
|
ScrollView.prototype._onPropMutate = function () {
|
|
@@ -259,7 +261,7 @@ var ScrollView = /** @class */ (function (_super) {
|
|
|
259
261
|
// are done for the first time
|
|
260
262
|
var delay = 0;
|
|
261
263
|
if (!!useDelay && this._firstStart) {
|
|
262
|
-
var progress =
|
|
264
|
+
var progress = clamp_1.default(useDelay.dir === 'x'
|
|
263
265
|
? (bounding.left - parentBounding.left) / parentBounding.width
|
|
264
266
|
: (bounding.top - parentBounding.top) / parentBounding.height, [0, 1]);
|
|
265
267
|
delay = progress * useDelay.max;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var vevet_dom_1 = require("vevet-dom");
|
|
7
7
|
var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
|
|
8
|
-
var
|
|
8
|
+
var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
|
|
9
9
|
var DraggerMove_1 = require("../../dragger/DraggerMove");
|
|
10
10
|
var SmoothScroll_1 = require("../smooth-scroll/SmoothScroll");
|
|
11
11
|
var Bar = /** @class */ (function () {
|
|
@@ -266,7 +266,7 @@ var Bar = /** @class */ (function () {
|
|
|
266
266
|
*/
|
|
267
267
|
Bar.prototype._renderThumb = function () {
|
|
268
268
|
// calculate progress
|
|
269
|
-
var progress =
|
|
269
|
+
var progress = clamp_1.default(this._scrollVal / this.scrollLine, [0, 1]);
|
|
270
270
|
// calculate transforms
|
|
271
271
|
var x = this.isX ? (this._outerWidth - this._thumbWidth) * progress : 0;
|
|
272
272
|
var y = this.isY ? (this._outerHeight - this._thumbHeight) * progress : 0;
|
|
@@ -285,11 +285,11 @@ var Bar = /** @class */ (function () {
|
|
|
285
285
|
// calculate thumb sizes
|
|
286
286
|
if (this.prop.autoSize) {
|
|
287
287
|
if (this.isX) {
|
|
288
|
-
var barSize =
|
|
288
|
+
var barSize = clamp_1.default(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
|
|
289
289
|
thumb.style.width = barSize + "px";
|
|
290
290
|
}
|
|
291
291
|
else {
|
|
292
|
-
var barSize =
|
|
292
|
+
var barSize = clamp_1.default(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
|
|
293
293
|
thumb.style.height = barSize + "px";
|
|
294
294
|
}
|
|
295
295
|
}
|
|
@@ -91,7 +91,7 @@ var ScrollBar = /** @class */ (function (_super) {
|
|
|
91
91
|
return _this;
|
|
92
92
|
}
|
|
93
93
|
ScrollBar.prototype._getDefaultProp = function () {
|
|
94
|
-
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, domParent: false, draggable: true, autoSize: true, autoHide: true, minSize: 50, optimizeCalculations: false, isDraggable: true, draggableScrollBehavior: 'smooth' });
|
|
94
|
+
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, domParent: false, draggable: true, autoSize: true, autoHide: true, minSize: 50, optimizeCalculations: false, resizeTimeout: 0, isDraggable: true, draggableScrollBehavior: 'smooth' });
|
|
95
95
|
};
|
|
96
96
|
Object.defineProperty(ScrollBar.prototype, "prefix", {
|
|
97
97
|
get: function () {
|
|
@@ -167,6 +167,8 @@ var ScrollBar = /** @class */ (function (_super) {
|
|
|
167
167
|
else {
|
|
168
168
|
this.addViewportCallback('', function () {
|
|
169
169
|
_this.resize();
|
|
170
|
+
}, {
|
|
171
|
+
timeout: this.prop.resizeTimeout,
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
174
|
this.resize();
|
|
@@ -34,7 +34,7 @@ var vevet_dom_1 = require("vevet-dom");
|
|
|
34
34
|
var normalize_wheel_1 = __importDefault(require("normalize-wheel"));
|
|
35
35
|
var Component_1 = require("../../../base/Component");
|
|
36
36
|
var AnimationFrame_1 = require("../../animation-frame/AnimationFrame");
|
|
37
|
-
var
|
|
37
|
+
var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
|
|
38
38
|
var math_1 = require("../../../utils/math");
|
|
39
39
|
/**
|
|
40
40
|
* Create smooth scrolling.
|
|
@@ -149,7 +149,7 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
149
149
|
? -this.prop.overscroll.max : 0;
|
|
150
150
|
var max = this.maxScrollableWidth
|
|
151
151
|
+ (!!this.prop.overscroll && this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
152
|
-
this._targetLeft =
|
|
152
|
+
this._targetLeft = clamp_1.default(val, [min, max]);
|
|
153
153
|
},
|
|
154
154
|
enumerable: false,
|
|
155
155
|
configurable: true
|
|
@@ -177,7 +177,7 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
177
177
|
? -this.prop.overscroll.max : 0;
|
|
178
178
|
var max = this.maxScrollableHeight
|
|
179
179
|
+ (!!this.prop.overscroll && !this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
180
|
-
this._targetTop =
|
|
180
|
+
this._targetTop = clamp_1.default(val, [min, max]);
|
|
181
181
|
},
|
|
182
182
|
enumerable: false,
|
|
183
183
|
configurable: true
|
|
@@ -258,7 +258,7 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
258
258
|
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { selectors: {
|
|
259
259
|
outer: "#" + this.prefix,
|
|
260
260
|
elements: false,
|
|
261
|
-
}, enabled: true, animationFrame: false, recalculateSizes: true, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
|
|
261
|
+
}, enabled: true, animationFrame: false, recalculateSizes: true, resizeTimeout: 0, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
|
|
262
262
|
lerp: 0.1,
|
|
263
263
|
lerpToFixed: 2,
|
|
264
264
|
approximation: 0.1,
|
|
@@ -280,6 +280,8 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
280
280
|
this.resize();
|
|
281
281
|
this.addViewportCallback('', function () {
|
|
282
282
|
_this.resize(true);
|
|
283
|
+
}, {
|
|
284
|
+
timeout: this.prop.resizeTimeout,
|
|
283
285
|
});
|
|
284
286
|
// wheel
|
|
285
287
|
this.addEventListeners(this.outer, 'wheel', function (e) {
|
|
@@ -310,8 +312,8 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
310
312
|
// get sizes
|
|
311
313
|
this._clientWidth = outer.clientWidth;
|
|
312
314
|
this._clientHeight = outer.clientHeight;
|
|
313
|
-
this._scrollWidth =
|
|
314
|
-
this._scrollHeight =
|
|
315
|
+
this._scrollWidth = clamp_1.default(container.clientWidth, [this.clientWidth, Infinity]);
|
|
316
|
+
this._scrollHeight = clamp_1.default(container.clientHeight, [this.clientHeight, Infinity]);
|
|
315
317
|
// force instant change
|
|
316
318
|
// it means that after resizing, scrolling will be instantaneous for a while
|
|
317
319
|
if (native) {
|
|
@@ -68,7 +68,7 @@ var SplitText = /** @class */ (function (_super) {
|
|
|
68
68
|
return _this;
|
|
69
69
|
}
|
|
70
70
|
SplitText.prototype._getDefaultProp = function () {
|
|
71
|
-
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: "#" + this.prefix, appendLetters: true, appendLines: false, viewportTarget: '' });
|
|
71
|
+
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: "#" + this.prefix, appendLetters: true, appendLines: false, viewportTarget: '', resizeTimeout: 0 });
|
|
72
72
|
};
|
|
73
73
|
Object.defineProperty(SplitText.prototype, "prefix", {
|
|
74
74
|
get: function () {
|
|
@@ -116,6 +116,8 @@ var SplitText = /** @class */ (function (_super) {
|
|
|
116
116
|
if (this.prop.appendLines) {
|
|
117
117
|
this.addViewportCallback(this.prop.viewportTarget, function () {
|
|
118
118
|
_this.splitText();
|
|
119
|
+
}, {
|
|
120
|
+
timeout: this.prop.resizeTimeout,
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
123
|
};
|
|
@@ -32,8 +32,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
exports.StaticTimeline = void 0;
|
|
33
33
|
var easing_progress_1 = __importDefault(require("easing-progress"));
|
|
34
34
|
var Component_1 = require("../../base/Component");
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var scoped_1 = __importDefault(require("../../utils/math/scoped"));
|
|
36
|
+
var clamp_1 = __importDefault(require("../../utils/math/clamp"));
|
|
37
37
|
/**
|
|
38
38
|
* StaticTimeline is the base class for Timeline itself.
|
|
39
39
|
* The difference between the coponents is that StaticTimeline has no animation:
|
|
@@ -118,7 +118,7 @@ var StaticTimeline = /** @class */ (function (_super) {
|
|
|
118
118
|
for (var index = 0, l = length; index < l; index += 1) {
|
|
119
119
|
var tm = this._nestedTimelines[index];
|
|
120
120
|
// calculate progress of this very timeline
|
|
121
|
-
var tmProgress =
|
|
121
|
+
var tmProgress = clamp_1.default(scoped_1.default(progressForNested, tm.prop.nestedScope), [0, 1]);
|
|
122
122
|
tm.progress = tmProgress;
|
|
123
123
|
}
|
|
124
124
|
};
|
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.Timeline = void 0;
|
|
33
33
|
var StaticTimeline_1 = require("./StaticTimeline");
|
|
34
|
-
var
|
|
34
|
+
var clamp_1 = __importDefault(require("../../utils/math/clamp"));
|
|
35
35
|
/**
|
|
36
36
|
* Timeline is an animation helper.
|
|
37
37
|
*/
|
|
@@ -149,7 +149,7 @@ var Timeline = /** @class */ (function (_super) {
|
|
|
149
149
|
this._animationFrameLastTime = currentTime;
|
|
150
150
|
// calculate current progress
|
|
151
151
|
var progressIterator = frameDiff / this.prop.duration / (isReversed ? -1 : 1);
|
|
152
|
-
var progressTarget =
|
|
152
|
+
var progressTarget = clamp_1.default(this.progress + progressIterator, [0, 1]);
|
|
153
153
|
this.progress = progressTarget;
|
|
154
154
|
// end animation
|
|
155
155
|
if ((progressTarget === 1 && !isReversed)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Clamp the value between two points
|
|
5
|
+
*/
|
|
6
|
+
function clamp(val, scope) {
|
|
7
|
+
if (scope === void 0) { scope = [0, 1]; }
|
|
8
|
+
if (val < scope[0]) {
|
|
9
|
+
return scope[0];
|
|
10
|
+
}
|
|
11
|
+
if (val > scope[1]) {
|
|
12
|
+
return scope[1];
|
|
13
|
+
}
|
|
14
|
+
return val;
|
|
15
|
+
}
|
|
16
|
+
exports.default = clamp;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var scoped_1 = __importDefault(require("./scoped"));
|
|
7
|
+
var clamp_1 = __importDefault(require("./clamp"));
|
|
8
|
+
/**
|
|
9
|
+
* Get progress relatively to the scope and clamp it within two points
|
|
10
|
+
*/
|
|
11
|
+
function clampScoped(val, scope, clampScope) {
|
|
12
|
+
if (scope === void 0) { scope = [0, 1]; }
|
|
13
|
+
if (clampScope === void 0) { clampScope = [0, 1]; }
|
|
14
|
+
return clamp_1.default(scoped_1.default(val, scope), clampScope);
|
|
15
|
+
}
|
|
16
|
+
exports.default = clampScoped;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Check if the value is within the scope
|
|
5
|
+
*/
|
|
6
|
+
function inScope(val, scopeValue) {
|
|
7
|
+
if (scopeValue === void 0) { scopeValue = [0, 1]; }
|
|
8
|
+
return val >= scopeValue[0] && val <= scopeValue[1];
|
|
9
|
+
}
|
|
10
|
+
exports.default = inScope;
|
|
@@ -3,14 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.wrap = exports.
|
|
7
|
-
var
|
|
8
|
-
exports.
|
|
6
|
+
exports.wrap = exports.clampScope = exports.inScope = exports.spreadScope = exports.scoped = exports.lerp = exports.clamp = void 0;
|
|
7
|
+
var clamp_1 = __importDefault(require("./clamp"));
|
|
8
|
+
exports.clamp = clamp_1.default;
|
|
9
9
|
var lerp_1 = __importDefault(require("./lerp"));
|
|
10
10
|
exports.lerp = lerp_1.default;
|
|
11
|
-
var
|
|
12
|
-
exports.
|
|
13
|
-
var
|
|
14
|
-
exports.
|
|
11
|
+
var scoped_1 = __importDefault(require("./scoped"));
|
|
12
|
+
exports.scoped = scoped_1.default;
|
|
13
|
+
var spreadScope_1 = __importDefault(require("./spreadScope"));
|
|
14
|
+
exports.spreadScope = spreadScope_1.default;
|
|
15
|
+
var inScope_1 = __importDefault(require("./inScope"));
|
|
16
|
+
exports.inScope = inScope_1.default;
|
|
17
|
+
var clampScope_1 = __importDefault(require("./clampScope"));
|
|
18
|
+
exports.clampScope = clampScope_1.default;
|
|
15
19
|
var wrap_1 = __importDefault(require("./wrap"));
|
|
16
20
|
exports.wrap = wrap_1.default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Get progress relatively to the scope.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* scope(.35, [0, 1]);
|
|
9
|
+
* // => .5
|
|
10
|
+
* scope(.35, [.25, 1]);
|
|
11
|
+
* // => .133
|
|
12
|
+
*/
|
|
13
|
+
function scoped(val, scopeValue) {
|
|
14
|
+
if (scopeValue === void 0) { scopeValue = [0, 1]; }
|
|
15
|
+
var result = (val - scopeValue[0]) / (scopeValue[1] - scopeValue[0]);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
exports.default = scoped;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Distribute scope progress among a certain quantity of timelines.
|
|
5
|
+
*/
|
|
6
|
+
function spreadScope(quantity, shift) {
|
|
7
|
+
var timelines = [];
|
|
8
|
+
// duration for each element
|
|
9
|
+
var duration = 1 / (quantity - shift * (quantity - 1));
|
|
10
|
+
// calculate timelines
|
|
11
|
+
for (var index = 0; index < quantity; index += 1) {
|
|
12
|
+
var start = (duration * (1 - shift)) * index;
|
|
13
|
+
var end = start + duration;
|
|
14
|
+
timelines.push([start, end]);
|
|
15
|
+
}
|
|
16
|
+
return timelines;
|
|
17
|
+
}
|
|
18
|
+
exports.default = spreadScope;
|
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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ScrollEventsBase } from './ScrollEventsBase';
|
|
2
2
|
import onScroll from '../../../utils/listeners/onScroll';
|
|
3
3
|
import { intersectionObserverSupported } from '../../../utils/listeners';
|
|
4
|
-
import
|
|
4
|
+
import clamp from '../../../utils/math/clamp';
|
|
5
5
|
import timeoutCallback from '../../../utils/common/timeoutCallback';
|
|
6
6
|
/**
|
|
7
7
|
* Elements into viewport
|
|
@@ -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 });
|
|
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
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Elements to seek
|
|
@@ -40,6 +40,8 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
40
40
|
this.resize();
|
|
41
41
|
this.addViewportCallback('', () => {
|
|
42
42
|
this.resize();
|
|
43
|
+
}, {
|
|
44
|
+
timeout: this.prop.resizeTimeout,
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
47
|
_onPropMutate() {
|
|
@@ -209,7 +211,7 @@ export class ScrollView extends ScrollEventsBase {
|
|
|
209
211
|
// are done for the first time
|
|
210
212
|
let delay = 0;
|
|
211
213
|
if (!!useDelay && this._firstStart) {
|
|
212
|
-
const progress =
|
|
214
|
+
const progress = clamp(useDelay.dir === 'x'
|
|
213
215
|
? (bounding.left - parentBounding.left) / parentBounding.width
|
|
214
216
|
: (bounding.top - parentBounding.top) / parentBounding.height, [0, 1]);
|
|
215
217
|
delay = progress * useDelay.max;
|
|
@@ -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 {
|
|
@@ -215,7 +215,7 @@ export default class Bar {
|
|
|
215
215
|
*/
|
|
216
216
|
_renderThumb() {
|
|
217
217
|
// calculate progress
|
|
218
|
-
const progress =
|
|
218
|
+
const progress = clamp(this._scrollVal / this.scrollLine, [0, 1]);
|
|
219
219
|
// calculate transforms
|
|
220
220
|
const x = this.isX ? (this._outerWidth - this._thumbWidth) * progress : 0;
|
|
221
221
|
const y = this.isY ? (this._outerHeight - this._thumbHeight) * progress : 0;
|
|
@@ -234,11 +234,11 @@ export default class Bar {
|
|
|
234
234
|
// calculate thumb sizes
|
|
235
235
|
if (this.prop.autoSize) {
|
|
236
236
|
if (this.isX) {
|
|
237
|
-
const barSize =
|
|
237
|
+
const barSize = clamp(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
|
|
238
238
|
thumb.style.width = `${barSize}px`;
|
|
239
239
|
}
|
|
240
240
|
else {
|
|
241
|
-
const barSize =
|
|
241
|
+
const barSize = clamp(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
|
|
242
242
|
thumb.style.height = `${barSize}px`;
|
|
243
243
|
}
|
|
244
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();
|
|
@@ -2,7 +2,7 @@ import { selectAll, selectOne, isElement, createElement, } from 'vevet-dom';
|
|
|
2
2
|
import normalizeWheel from 'normalize-wheel';
|
|
3
3
|
import { Component } from '../../../base/Component';
|
|
4
4
|
import { AnimationFrame } from '../../animation-frame/AnimationFrame';
|
|
5
|
-
import
|
|
5
|
+
import clamp from '../../../utils/math/clamp';
|
|
6
6
|
import { lerp } from '../../../utils/math';
|
|
7
7
|
/**
|
|
8
8
|
* Create smooth scrolling.
|
|
@@ -90,7 +90,7 @@ export class SmoothScroll extends Component {
|
|
|
90
90
|
? -this.prop.overscroll.max : 0;
|
|
91
91
|
const max = this.maxScrollableWidth
|
|
92
92
|
+ (!!this.prop.overscroll && this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
93
|
-
this._targetLeft =
|
|
93
|
+
this._targetLeft = clamp(val, [min, max]);
|
|
94
94
|
}
|
|
95
95
|
get targetLeftBound() {
|
|
96
96
|
return this._targetLeft;
|
|
@@ -110,7 +110,7 @@ export class SmoothScroll extends Component {
|
|
|
110
110
|
? -this.prop.overscroll.max : 0;
|
|
111
111
|
const max = this.maxScrollableHeight
|
|
112
112
|
+ (!!this.prop.overscroll && !this.prop.isHorizontal ? this.prop.overscroll.max : 0);
|
|
113
|
-
this._targetTop =
|
|
113
|
+
this._targetTop = clamp(val, [min, max]);
|
|
114
114
|
}
|
|
115
115
|
get targetTopBound() {
|
|
116
116
|
return this._targetTop;
|
|
@@ -159,7 +159,7 @@ export class SmoothScroll extends Component {
|
|
|
159
159
|
return Object.assign(Object.assign({}, super._getDefaultProp()), { selectors: {
|
|
160
160
|
outer: `#${this.prefix}`,
|
|
161
161
|
elements: false,
|
|
162
|
-
}, enabled: true, animationFrame: false, recalculateSizes: true, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
|
|
162
|
+
}, enabled: true, animationFrame: false, recalculateSizes: true, resizeTimeout: 0, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
|
|
163
163
|
lerp: 0.1,
|
|
164
164
|
lerpToFixed: 2,
|
|
165
165
|
approximation: 0.1,
|
|
@@ -180,6 +180,8 @@ export class SmoothScroll extends Component {
|
|
|
180
180
|
this.resize();
|
|
181
181
|
this.addViewportCallback('', () => {
|
|
182
182
|
this.resize(true);
|
|
183
|
+
}, {
|
|
184
|
+
timeout: this.prop.resizeTimeout,
|
|
183
185
|
});
|
|
184
186
|
// wheel
|
|
185
187
|
this.addEventListeners(this.outer, 'wheel', (e) => {
|
|
@@ -209,8 +211,8 @@ export class SmoothScroll extends Component {
|
|
|
209
211
|
// get sizes
|
|
210
212
|
this._clientWidth = outer.clientWidth;
|
|
211
213
|
this._clientHeight = outer.clientHeight;
|
|
212
|
-
this._scrollWidth =
|
|
213
|
-
this._scrollHeight =
|
|
214
|
+
this._scrollWidth = clamp(container.clientWidth, [this.clientWidth, Infinity]);
|
|
215
|
+
this._scrollHeight = clamp(container.clientHeight, [this.clientHeight, Infinity]);
|
|
214
216
|
// force instant change
|
|
215
217
|
// it means that after resizing, scrolling will be instantaneous for a while
|
|
216
218
|
if (native) {
|
|
@@ -36,7 +36,7 @@ export class SplitText extends Component {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
_getDefaultProp() {
|
|
39
|
-
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: `#${this.prefix}`, appendLetters: true, appendLines: false, viewportTarget: '' });
|
|
39
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: `#${this.prefix}`, appendLetters: true, appendLines: false, viewportTarget: '', resizeTimeout: 0 });
|
|
40
40
|
}
|
|
41
41
|
get prefix() {
|
|
42
42
|
return `${this._app.prefix}split-text`;
|
|
@@ -63,6 +63,8 @@ export class SplitText extends Component {
|
|
|
63
63
|
if (this.prop.appendLines) {
|
|
64
64
|
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
65
65
|
this.splitText();
|
|
66
|
+
}, {
|
|
67
|
+
timeout: this.prop.resizeTimeout,
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import easingProgress from 'easing-progress';
|
|
2
2
|
import { Component } from '../../base/Component';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import scoped from '../../utils/math/scoped';
|
|
4
|
+
import clamp from '../../utils/math/clamp';
|
|
5
5
|
/**
|
|
6
6
|
* StaticTimeline is the base class for Timeline itself.
|
|
7
7
|
* The difference between the coponents is that StaticTimeline has no animation:
|
|
@@ -75,7 +75,7 @@ export class StaticTimeline extends Component {
|
|
|
75
75
|
for (let index = 0, l = length; index < l; index += 1) {
|
|
76
76
|
const tm = this._nestedTimelines[index];
|
|
77
77
|
// calculate progress of this very timeline
|
|
78
|
-
const tmProgress =
|
|
78
|
+
const tmProgress = clamp(scoped(progressForNested, tm.prop.nestedScope), [0, 1]);
|
|
79
79
|
tm.progress = tmProgress;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StaticTimeline } from './StaticTimeline';
|
|
2
|
-
import
|
|
2
|
+
import clamp from '../../utils/math/clamp';
|
|
3
3
|
/**
|
|
4
4
|
* Timeline is an animation helper.
|
|
5
5
|
*/
|
|
@@ -102,7 +102,7 @@ export class Timeline extends StaticTimeline {
|
|
|
102
102
|
this._animationFrameLastTime = currentTime;
|
|
103
103
|
// calculate current progress
|
|
104
104
|
const progressIterator = frameDiff / this.prop.duration / (isReversed ? -1 : 1);
|
|
105
|
-
const progressTarget =
|
|
105
|
+
const progressTarget = clamp(this.progress + progressIterator, [0, 1]);
|
|
106
106
|
this.progress = progressTarget;
|
|
107
107
|
// end animation
|
|
108
108
|
if ((progressTarget === 1 && !isReversed)
|