vevet 2.0.1-dev.3 → 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/canvas/Ctx2DPrerender.js +20 -2
- package/build/cjs/components/loading/ProgressPreloader.js +14 -2
- package/build/cjs/components/page/Page.js +36 -8
- package/build/cjs/components/scroll/plugins/SmoothScrollDragPlugin.js +40 -5
- package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +9 -0
- package/build/cjs/components/scroll/scrollable/ScrollView.js +124 -66
- package/build/cjs/components/scroll/scrollbar/Bar.js +12 -6
- package/build/cjs/components/scroll/scrollbar/ScrollBar.js +3 -1
- package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +19 -9
- package/build/cjs/components/text/SplitText.js +25 -3
- package/build/cjs/components/timeline/StaticTimeline.js +3 -3
- package/build/cjs/components/timeline/Timeline.js +3 -2
- package/build/cjs/handlers/wheel/WheelHandler.js +195 -0
- package/build/cjs/index.js +3 -1
- package/build/cjs/utils/listeners/onScroll.js +65 -25
- package/build/cjs/utils/math/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 +13 -5
- package/build/cjs/utils/math/scoped.js +18 -0
- package/build/cjs/utils/math/spreadScope.js +18 -0
- package/build/cjs/utils/math/spreadScopeProgress.js +18 -0
- package/build/cjs/utils/math/wrap.js +13 -0
- package/build/es/base/Module.js +2 -4
- package/build/es/components/animation-frame/AnimationFrame.js +2 -2
- package/build/es/components/canvas/Ctx2D.js +6 -2
- package/build/es/components/canvas/Ctx2DPrerender.js +20 -2
- package/build/es/components/loading/ProgressPreloader.js +14 -2
- package/build/es/components/page/Page.js +32 -8
- package/build/es/components/scroll/plugins/SmoothScrollDragPlugin.js +40 -5
- package/build/es/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +9 -0
- package/build/es/components/scroll/scrollable/ScrollView.js +113 -61
- package/build/es/components/scroll/scrollbar/Bar.js +12 -6
- package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
- package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +19 -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 +3 -2
- package/build/es/handlers/wheel/WheelHandler.js +153 -0
- package/build/es/index.js +2 -1
- package/build/es/utils/listeners/onScroll.js +64 -25
- package/build/es/utils/math/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 +7 -3
- package/build/es/utils/math/scoped.js +14 -0
- package/build/es/utils/math/spreadScope.js +15 -0
- package/build/es/utils/math/spreadScopeProgress.js +15 -0
- package/build/es/utils/math/wrap.js +10 -0
- package/build/types/base/Module.d.ts.map +1 -1
- package/build/types/components/canvas/Ctx2D.d.ts +9 -0
- package/build/types/components/canvas/Ctx2D.d.ts.map +1 -1
- package/build/types/components/canvas/Ctx2DPrerender.d.ts +1 -1
- package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -1
- package/build/types/components/loading/ProgressPreloader.d.ts +7 -0
- package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
- package/build/types/components/page/Page.d.ts +2 -0
- package/build/types/components/page/Page.d.ts.map +1 -1
- package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts +11 -0
- package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts.map +1 -1
- package/build/types/components/scroll/plugins/SmoothScrollKeyboardPlugin.d.ts.map +1 -1
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +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/components/timeline/Timeline.d.ts.map +1 -1
- package/build/types/handlers/wheel/WheelHandler.d.ts +100 -0
- package/build/types/handlers/wheel/WheelHandler.d.ts.map +1 -0
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils/listeners/onScroll.d.ts +13 -5
- package/build/types/utils/listeners/onScroll.d.ts.map +1 -1
- package/build/types/utils/math/clamp.d.ts +5 -0
- package/build/types/utils/math/clamp.d.ts.map +1 -0
- package/build/types/utils/math/clampScope.d.ts +5 -0
- package/build/types/utils/math/clampScope.d.ts.map +1 -0
- package/build/types/utils/math/inScope.d.ts +5 -0
- package/build/types/utils/math/inScope.d.ts.map +1 -0
- package/build/types/utils/math/index.d.ts +7 -3
- package/build/types/utils/math/index.d.ts.map +1 -1
- package/build/types/utils/math/scoped.d.ts +12 -0
- package/build/types/utils/math/scoped.d.ts.map +1 -0
- package/build/types/utils/math/spreadScope.d.ts +5 -0
- package/build/types/utils/math/spreadScope.d.ts.map +1 -0
- package/build/types/utils/math/spreadScopeProgress.d.ts +5 -0
- package/build/types/utils/math/spreadScopeProgress.d.ts.map +1 -0
- package/build/types/utils/math/wrap.d.ts +5 -0
- package/build/types/utils/math/wrap.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/sass/components/cursor/_custom-cursor.scss +0 -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/canvas/Ctx2DPrerender.ts +23 -6
- package/src/ts/components/loading/ProgressPreloader.ts +21 -2
- package/src/ts/components/page/Page.ts +34 -8
- package/src/ts/components/scroll/plugins/SmoothScrollDragPlugin.ts +58 -5
- package/src/ts/components/scroll/plugins/SmoothScrollKeyboardPlugin.ts +12 -0
- package/src/ts/components/scroll/scrollable/ScrollView.ts +157 -85
- package/src/ts/components/scroll/scrollbar/Bar.ts +12 -6
- package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
- package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +24 -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 +3 -2
- package/src/ts/handlers/wheel/WheelHandler.ts +269 -0
- package/src/ts/index.ts +4 -0
- package/src/ts/utils/listeners/onScroll.ts +105 -34
- package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
- package/src/ts/utils/math/clampScope.ts +16 -0
- package/src/ts/utils/math/inScope.ts +9 -0
- package/src/ts/utils/math/index.ts +12 -4
- package/src/ts/utils/math/scoped.ts +17 -0
- package/src/ts/utils/math/spreadScope.ts +18 -0
- package/src/ts/utils/math/wrap.ts +18 -0
- package/src/ts/utils/math/scopeProgress.ts +0 -23
|
@@ -0,0 +1,195 @@
|
|
|
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.WheelHandler = void 0;
|
|
33
|
+
var vevet_dom_1 = require("vevet-dom");
|
|
34
|
+
var normalize_wheel_1 = __importDefault(require("normalize-wheel"));
|
|
35
|
+
var Module_1 = require("../../base/Module");
|
|
36
|
+
/**
|
|
37
|
+
* Wheel events: up & down, left & right without repeating
|
|
38
|
+
|
|
39
|
+
*/
|
|
40
|
+
var WheelHandler = /** @class */ (function (_super) {
|
|
41
|
+
__extends(WheelHandler, _super);
|
|
42
|
+
function WheelHandler(initialProp, init) {
|
|
43
|
+
if (init === void 0) { init = true; }
|
|
44
|
+
var _this = _super.call(this, initialProp, false) || this;
|
|
45
|
+
_this._wheelListener = undefined;
|
|
46
|
+
_this._lockWheel = false;
|
|
47
|
+
if (init) {
|
|
48
|
+
_this.init();
|
|
49
|
+
}
|
|
50
|
+
return _this;
|
|
51
|
+
}
|
|
52
|
+
WheelHandler.prototype._getDefaultProp = function () {
|
|
53
|
+
return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: false, enabled: true, stopPropagation: false, threshold: 20 });
|
|
54
|
+
};
|
|
55
|
+
Object.defineProperty(WheelHandler.prototype, "container", {
|
|
56
|
+
/**
|
|
57
|
+
* Listener contianer
|
|
58
|
+
*/
|
|
59
|
+
get: function () {
|
|
60
|
+
if (!this.prop.container) {
|
|
61
|
+
return window;
|
|
62
|
+
}
|
|
63
|
+
return this.prop.container;
|
|
64
|
+
},
|
|
65
|
+
enumerable: false,
|
|
66
|
+
configurable: true
|
|
67
|
+
});
|
|
68
|
+
// Set Module Events
|
|
69
|
+
WheelHandler.prototype._setEvents = function () {
|
|
70
|
+
_super.prototype._setEvents.call(this);
|
|
71
|
+
if (!(this.container instanceof Window)) {
|
|
72
|
+
this._listeners.push(vevet_dom_1.addEventListener(this.container, 'mouseenter', this._handleMouseEnter.bind(this)));
|
|
73
|
+
this._listeners.push(vevet_dom_1.addEventListener(this.container, 'mouseleave', this._handleMouseLeave.bind(this)));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this._toggleWheelEvent();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
WheelHandler.prototype._onPropMutate = function () {
|
|
80
|
+
_super.prototype._onPropMutate.call(this);
|
|
81
|
+
this._toggleWheelEvent();
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Handle element mouse enter
|
|
85
|
+
*/
|
|
86
|
+
WheelHandler.prototype._handleMouseEnter = function () {
|
|
87
|
+
if (this.prop.enabled) {
|
|
88
|
+
this._createWheelEvent();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Handle element mouse leave
|
|
93
|
+
*/
|
|
94
|
+
WheelHandler.prototype._handleMouseLeave = function () {
|
|
95
|
+
this._destroyWheelEvent();
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Set wheel event
|
|
99
|
+
*/
|
|
100
|
+
WheelHandler.prototype._toggleWheelEvent = function () {
|
|
101
|
+
if (this.prop.enabled) {
|
|
102
|
+
this._createWheelEvent();
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this._destroyWheelEvent();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Create a wheel event
|
|
110
|
+
*/
|
|
111
|
+
WheelHandler.prototype._createWheelEvent = function () {
|
|
112
|
+
if (this._wheelListener) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// reset gaining
|
|
116
|
+
this._lockWheel = false;
|
|
117
|
+
if (this._lockWheelTimeout) {
|
|
118
|
+
clearTimeout(this._lockWheelTimeout);
|
|
119
|
+
}
|
|
120
|
+
// create a listener
|
|
121
|
+
this._wheelListener = vevet_dom_1.addEventListener(this.container, 'wheel',
|
|
122
|
+
// throttle(this._handleWheel.bind(this), 200),
|
|
123
|
+
this._handleWheel.bind(this));
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Destroy the wheel event
|
|
127
|
+
*/
|
|
128
|
+
WheelHandler.prototype._destroyWheelEvent = function () {
|
|
129
|
+
if (!this._wheelListener) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this._wheelListener.remove();
|
|
133
|
+
this._wheelListener = undefined;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Handle wheel event
|
|
137
|
+
*/
|
|
138
|
+
WheelHandler.prototype._handleWheel = function (evt) {
|
|
139
|
+
var _this = this;
|
|
140
|
+
if (!this._wheelListener) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// stop propagation
|
|
144
|
+
if (this.prop.stopPropagation) {
|
|
145
|
+
evt.preventDefault();
|
|
146
|
+
evt.stopPropagation();
|
|
147
|
+
}
|
|
148
|
+
// if locked
|
|
149
|
+
if (this._lockWheel) {
|
|
150
|
+
if (this._lockWheelTimeout) {
|
|
151
|
+
clearTimeout(this._lockWheelTimeout);
|
|
152
|
+
}
|
|
153
|
+
this._lockWheelTimeout = setTimeout(function () {
|
|
154
|
+
_this._lockWheel = false;
|
|
155
|
+
}, 300);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// data
|
|
159
|
+
var delta = normalize_wheel_1.default(evt);
|
|
160
|
+
var threshold = this.prop.threshold;
|
|
161
|
+
// launch events
|
|
162
|
+
var eventFired = false;
|
|
163
|
+
// Y
|
|
164
|
+
if (delta.pixelY > threshold) {
|
|
165
|
+
this._callbacks.tbt('down', false);
|
|
166
|
+
eventFired = true;
|
|
167
|
+
}
|
|
168
|
+
else if (delta.pixelY < threshold * -1) {
|
|
169
|
+
this._callbacks.tbt('up', false);
|
|
170
|
+
eventFired = true;
|
|
171
|
+
}
|
|
172
|
+
// X
|
|
173
|
+
if (delta.pixelX > threshold) {
|
|
174
|
+
this._callbacks.tbt('right', false);
|
|
175
|
+
eventFired = true;
|
|
176
|
+
}
|
|
177
|
+
else if (delta.pixelX < threshold * -1) {
|
|
178
|
+
this._callbacks.tbt('left', false);
|
|
179
|
+
eventFired = true;
|
|
180
|
+
}
|
|
181
|
+
// lock events
|
|
182
|
+
if (eventFired) {
|
|
183
|
+
this._lockWheel = true;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Destroy the module
|
|
188
|
+
*/
|
|
189
|
+
WheelHandler.prototype._destroy = function () {
|
|
190
|
+
_super.prototype._destroy.call(this);
|
|
191
|
+
this._destroyWheelEvent();
|
|
192
|
+
};
|
|
193
|
+
return WheelHandler;
|
|
194
|
+
}(Module_1.Module));
|
|
195
|
+
exports.WheelHandler = WheelHandler;
|
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.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.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"));
|
|
@@ -43,6 +43,8 @@ var Plugin_1 = require("./base/Plugin");
|
|
|
43
43
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return Plugin_1.Plugin; } });
|
|
44
44
|
var Page_1 = require("./components/page/Page");
|
|
45
45
|
Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return Page_1.Page; } });
|
|
46
|
+
var WheelHandler_1 = require("./handlers/wheel/WheelHandler");
|
|
47
|
+
Object.defineProperty(exports, "WheelHandler", { enumerable: true, get: function () { return WheelHandler_1.WheelHandler; } });
|
|
46
48
|
var AnimationFrame_1 = require("./components/animation-frame/AnimationFrame");
|
|
47
49
|
Object.defineProperty(exports, "AnimationFrame", { enumerable: true, get: function () { return AnimationFrame_1.AnimationFrame; } });
|
|
48
50
|
var StaticTimeline_1 = require("./components/timeline/StaticTimeline");
|
|
@@ -2,45 +2,85 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var vevet_dom_1 = require("vevet-dom");
|
|
4
4
|
var SmoothScroll_1 = require("../../components/scroll/smooth-scroll/SmoothScroll");
|
|
5
|
+
var common_1 = require("../common");
|
|
6
|
+
var instances = [];
|
|
5
7
|
/**
|
|
6
8
|
* Add OnScroll event
|
|
7
9
|
*/
|
|
8
|
-
function onScroll(
|
|
9
|
-
var
|
|
10
|
-
if
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
function onScroll(_a) {
|
|
11
|
+
var container = _a.container, callback = _a.callback, _b = _a.isPassive, isPassive = _b === void 0 ? false : _b;
|
|
12
|
+
// check if listeners for this element already exist
|
|
13
|
+
var instance = instances.find(function (data) { return (data.container === container && data.isPassive === isPassive); });
|
|
14
|
+
var callbackId = common_1.randID('scroll-event');
|
|
15
|
+
// if a listener exists, we just add a new callback to its stack
|
|
16
|
+
if (instance) {
|
|
17
|
+
instance.callbacks.push({
|
|
18
|
+
id: callbackId,
|
|
19
|
+
callback: callback,
|
|
16
20
|
});
|
|
17
21
|
}
|
|
18
22
|
else {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
// otherwise we create a new instance
|
|
24
|
+
instance = {
|
|
25
|
+
id: common_1.randID('scroll-event-instance'),
|
|
26
|
+
container: container,
|
|
27
|
+
callbacks: [{
|
|
28
|
+
id: callbackId,
|
|
29
|
+
callback: callback,
|
|
30
|
+
}],
|
|
31
|
+
isPassive: isPassive,
|
|
32
|
+
listeners: [],
|
|
33
|
+
};
|
|
34
|
+
instances.push(instance);
|
|
35
|
+
// vars
|
|
36
|
+
var listeners = instance.listeners;
|
|
37
|
+
// smooth scroll events
|
|
38
|
+
if (container instanceof SmoothScroll_1.SmoothScroll) {
|
|
39
|
+
listeners.push(container.addCallback('scroll', function () {
|
|
40
|
+
var scrollTop = container.scrollTop, scrollLeft = container.scrollLeft;
|
|
41
|
+
for (var index = 0; index < instance.callbacks.length; index += 1) {
|
|
42
|
+
instance.callbacks[index].callback({
|
|
43
|
+
scrollTop: scrollTop,
|
|
44
|
+
scrollLeft: scrollLeft,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
22
48
|
}
|
|
23
49
|
else {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
listeners.push(vevet_dom_1.addEventListener(
|
|
28
|
-
var scrollTop =
|
|
29
|
-
?
|
|
30
|
-
var scrollLeft =
|
|
31
|
-
?
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
// dom scroll events
|
|
51
|
+
var isWindow_1 = container instanceof Window;
|
|
52
|
+
var domContainer_1 = vevet_dom_1.selectOne(container);
|
|
53
|
+
listeners.push(vevet_dom_1.addEventListener(domContainer_1, 'scroll', function () {
|
|
54
|
+
var scrollTop = isWindow_1
|
|
55
|
+
? domContainer_1.pageYOffset : domContainer_1.scrollTop;
|
|
56
|
+
var scrollLeft = isWindow_1
|
|
57
|
+
? domContainer_1.pageXOffset : domContainer_1.scrollLeft;
|
|
58
|
+
for (var index = 0; index < instance.callbacks.length; index += 1) {
|
|
59
|
+
instance.callbacks[index].callback({
|
|
60
|
+
scrollTop: scrollTop,
|
|
61
|
+
scrollLeft: scrollLeft,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
passive: isPassive,
|
|
36
66
|
}));
|
|
37
67
|
}
|
|
38
68
|
}
|
|
39
69
|
return {
|
|
40
70
|
remove: function () {
|
|
41
|
-
|
|
42
|
-
|
|
71
|
+
var newCallbacks = instance.callbacks.filter(function (item) {
|
|
72
|
+
if (item.id !== callbackId) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
43
76
|
});
|
|
77
|
+
instance.callbacks = newCallbacks;
|
|
78
|
+
if (newCallbacks.length === 0) {
|
|
79
|
+
instance.listeners.forEach(function (listener) {
|
|
80
|
+
listener.remove();
|
|
81
|
+
});
|
|
82
|
+
instances = instances.filter(function (item) { return item.id !== instance.id; });
|
|
83
|
+
}
|
|
44
84
|
},
|
|
45
85
|
};
|
|
46
86
|
}
|
|
@@ -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,10 +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.
|
|
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.
|
|
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;
|
|
19
|
+
var wrap_1 = __importDefault(require("./wrap"));
|
|
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;
|
|
@@ -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 spreadScopeProgress(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 = spreadScopeProgress;
|
|
@@ -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
|
}
|
|
@@ -15,14 +15,32 @@ export class Ctx2DPrerender extends Ctx2D {
|
|
|
15
15
|
this._prerender();
|
|
16
16
|
}
|
|
17
17
|
_prerender() {
|
|
18
|
+
// check if can render
|
|
19
|
+
if (this.width === 0 || this.height === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
18
22
|
// check if media exists
|
|
19
23
|
const { media } = this.prop;
|
|
20
24
|
if (!media) {
|
|
21
25
|
return;
|
|
22
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
|
+
}
|
|
23
39
|
// get media sizes
|
|
24
40
|
const size = getPos({
|
|
25
|
-
source
|
|
41
|
+
source,
|
|
42
|
+
sourceWidth,
|
|
43
|
+
sourceHeight,
|
|
26
44
|
rule: this.prop.posRule,
|
|
27
45
|
scale: 1,
|
|
28
46
|
width: this.width,
|
|
@@ -30,7 +48,7 @@ export class Ctx2DPrerender extends Ctx2D {
|
|
|
30
48
|
});
|
|
31
49
|
this._ctx.clearRect(0, 0, this.width, this.height);
|
|
32
50
|
// render the media
|
|
33
|
-
this._ctx.drawImage(
|
|
51
|
+
this._ctx.drawImage(source, size.x, size.y, size.width, size.height);
|
|
34
52
|
// launch callbacks on prerender
|
|
35
53
|
this.callbacks.tbt('prerender', false);
|
|
36
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
|