vevet 3.0.0-beta.2 → 3.0.0-beta.4
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/lib/cjs/Application/index.js.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/Application/events/PageLoad/index.js +28 -54
- package/lib/esm/Application/events/PageLoad/index.js.map +1 -1
- package/lib/esm/Application/events/Viewport/index.js +107 -180
- package/lib/esm/Application/events/Viewport/index.js.map +1 -1
- package/lib/esm/Application/index.js +96 -178
- package/lib/esm/Application/index.js.map +1 -1
- package/lib/esm/base/Callbacks/index.js +45 -78
- package/lib/esm/base/Callbacks/index.js.map +1 -1
- package/lib/esm/base/Component/index.js +10 -31
- package/lib/esm/base/Component/index.js.map +1 -1
- package/lib/esm/base/Module/index.js +77 -132
- package/lib/esm/base/Module/index.js.map +1 -1
- package/lib/esm/base/MutableProps/index.js +30 -49
- package/lib/esm/base/MutableProps/index.js.map +1 -1
- package/lib/esm/base/Plugin/index.js +13 -35
- package/lib/esm/base/Plugin/index.js.map +1 -1
- package/lib/esm/components/AnimationFrame/index.js +55 -98
- package/lib/esm/components/AnimationFrame/index.js.map +1 -1
- package/lib/esm/components/BaseTimeline/index.js +41 -88
- package/lib/esm/components/BaseTimeline/index.js.map +1 -1
- package/lib/esm/components/Ctx2D/index.js +82 -150
- package/lib/esm/components/Ctx2D/index.js.map +1 -1
- package/lib/esm/components/Ctx2DPrerender/index.js +20 -54
- package/lib/esm/components/Ctx2DPrerender/index.js.map +1 -1
- package/lib/esm/components/CustomCursor/index.js +149 -216
- package/lib/esm/components/CustomCursor/index.js.map +1 -1
- package/lib/esm/components/DraggerBase/index.js +98 -164
- package/lib/esm/components/DraggerBase/index.js.map +1 -1
- package/lib/esm/components/DraggerDirection/index.js +10 -42
- package/lib/esm/components/DraggerDirection/index.js.map +1 -1
- package/lib/esm/components/DraggerMove/index.js +42 -83
- package/lib/esm/components/DraggerMove/index.js.map +1 -1
- package/lib/esm/components/Preloader/index.js +77 -135
- package/lib/esm/components/Preloader/index.js.map +1 -1
- package/lib/esm/components/ProgressPreloader/index.js +112 -190
- package/lib/esm/components/ProgressPreloader/index.js.map +1 -1
- package/lib/esm/components/ProgressPreloader/utils/preloadCustomElement.js +9 -10
- package/lib/esm/components/ProgressPreloader/utils/preloadCustomElement.js.map +1 -1
- package/lib/esm/components/ProgressPreloader/utils/preloadImage.js +3 -3
- package/lib/esm/components/ProgressPreloader/utils/preloadImage.js.map +1 -1
- package/lib/esm/components/ProgressPreloader/utils/preloadVideo.js +2 -2
- package/lib/esm/components/ProgressPreloader/utils/preloadVideo.js.map +1 -1
- package/lib/esm/components/ScrollBar/Bar/index.js +90 -136
- package/lib/esm/components/ScrollBar/Bar/index.js.map +1 -1
- package/lib/esm/components/ScrollBar/index.js +70 -118
- package/lib/esm/components/ScrollBar/index.js.map +1 -1
- package/lib/esm/components/ScrollView/index.js +103 -154
- package/lib/esm/components/ScrollView/index.js.map +1 -1
- package/lib/esm/components/SectionScrollProgress/index.js +95 -170
- package/lib/esm/components/SectionScrollProgress/index.js.map +1 -1
- package/lib/esm/components/SmoothScroll/AnimatonFrame.js +20 -37
- package/lib/esm/components/SmoothScroll/AnimatonFrame.js.map +1 -1
- package/lib/esm/components/SmoothScroll/Elements.js +42 -59
- package/lib/esm/components/SmoothScroll/Elements.js.map +1 -1
- package/lib/esm/components/SmoothScroll/index.js +205 -304
- package/lib/esm/components/SmoothScroll/index.js.map +1 -1
- package/lib/esm/components/SmoothScrollDragPlugin/index.js +48 -86
- package/lib/esm/components/SmoothScrollDragPlugin/index.js.map +1 -1
- package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js +34 -70
- package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
- package/lib/esm/components/SplitText/index.js +117 -177
- package/lib/esm/components/SplitText/index.js.map +1 -1
- package/lib/esm/components/Timeline/index.js +45 -88
- package/lib/esm/components/Timeline/index.js.map +1 -1
- package/lib/esm/utils/common/mergeWithoutArrays.js +1 -1
- package/lib/esm/utils/common/mergeWithoutArrays.js.map +1 -1
- package/lib/esm/utils/common/normalizedTimeoutCallback.js +3 -3
- package/lib/esm/utils/common/normalizedTimeoutCallback.js.map +1 -1
- package/lib/esm/utils/common/pickObjectProps.js +2 -2
- package/lib/esm/utils/common/pickObjectProps.js.map +1 -1
- package/lib/esm/utils/common/times.js +2 -2
- package/lib/esm/utils/common/times.js.map +1 -1
- package/lib/esm/utils/common/uid.js +3 -4
- package/lib/esm/utils/common/uid.js.map +1 -1
- package/lib/esm/utils/image/load.js +15 -26
- package/lib/esm/utils/image/load.js.map +1 -1
- package/lib/esm/utils/image/pathsToProps.js +5 -5
- package/lib/esm/utils/image/pathsToProps.js.map +1 -1
- package/lib/esm/utils/image/sizesToSrcSet.js +5 -5
- package/lib/esm/utils/image/sizesToSrcSet.js.map +1 -1
- package/lib/esm/utils/internal/fetchWebpSupport.js +3 -3
- package/lib/esm/utils/internal/fetchWebpSupport.js.map +1 -1
- package/lib/esm/utils/internal/getDeviceInfo.js +7 -7
- package/lib/esm/utils/internal/getDeviceInfo.js.map +1 -1
- package/lib/esm/utils/internal/onResize.js +13 -16
- package/lib/esm/utils/internal/onResize.js.map +1 -1
- package/lib/esm/utils/math/clamp.js +1 -2
- package/lib/esm/utils/math/clamp.js.map +1 -1
- package/lib/esm/utils/math/clampScope.js +1 -3
- package/lib/esm/utils/math/clampScope.js.map +1 -1
- package/lib/esm/utils/math/easing.js +1 -5
- package/lib/esm/utils/math/easing.js.map +1 -1
- package/lib/esm/utils/math/inScope.js +1 -2
- package/lib/esm/utils/math/inScope.js.map +1 -1
- package/lib/esm/utils/math/lerp.js +3 -4
- package/lib/esm/utils/math/lerp.js.map +1 -1
- package/lib/esm/utils/math/normalizeNestedScope.js +1 -1
- package/lib/esm/utils/math/normalizeNestedScope.js.map +1 -1
- package/lib/esm/utils/math/scoped.js +2 -3
- package/lib/esm/utils/math/scoped.js.map +1 -1
- package/lib/esm/utils/math/spreadScope.js +5 -5
- package/lib/esm/utils/math/spreadScope.js.map +1 -1
- package/lib/esm/utils/math/wrap.js +2 -2
- package/lib/esm/utils/math/wrap.js.map +1 -1
- package/lib/esm/utils/scroll/getScrollValues.js +5 -6
- package/lib/esm/utils/scroll/getScrollValues.js.map +1 -1
- package/lib/esm/utils/scroll/onScroll.js +20 -23
- package/lib/esm/utils/scroll/onScroll.js.map +1 -1
- package/lib/esm/utils/scroll/scrollTo.js +10 -12
- package/lib/esm/utils/scroll/scrollTo.js.map +1 -1
- package/lib/esm/utils/scroll/scrollToElement.js +8 -19
- package/lib/esm/utils/scroll/scrollToElement.js.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/esm/vevet.js +1 -1
- package/lib/esm/vevet.js.map +1 -1
- package/lib/types/Application/index.d.ts +3 -3
- package/lib/types/Application/index.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/Application/index.ts +3 -3
- package/src/version.ts +1 -1
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
1
|
import { selectOne } from 'vevet-dom';
|
|
28
2
|
import { Component as ComponentClass } from '../../base/Component';
|
|
29
3
|
import { clamp, lerp } from '../../utils/math';
|
|
@@ -34,282 +8,213 @@ import { onResize } from '../../utils/internal/onResize';
|
|
|
34
8
|
/**
|
|
35
9
|
* Smooth scrolling
|
|
36
10
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
11
|
+
export class SmoothScroll extends ComponentClass {
|
|
12
|
+
_getDefaultProps() {
|
|
13
|
+
return Object.assign(Object.assign({}, super._getDefaultProps()), { container: `#${this.prefix}`, elements: false, animationFrame: false, viewportTarget: 'any', resizeDebounce: 0, hasWillChange: true, translatePrecision: 2, isEnabled: true, hasWheel: true, direction: 'vertical', isInverseHandlerDirection: false, isAutoStop: true, hasStopPropagation: true, lerp: 0.1, isFpsNormalized: true, lerpApproximation: 0.1 });
|
|
14
|
+
}
|
|
15
|
+
get prefix() {
|
|
16
|
+
return `${this.app.prefix}smooth-scroll`;
|
|
17
|
+
}
|
|
18
|
+
/** Scroll container */
|
|
19
|
+
get container() {
|
|
20
|
+
return this._container;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Scroll wrapper. If the element does not exist indide the `container`,
|
|
24
|
+
* it will be created automatically
|
|
25
|
+
*/
|
|
26
|
+
get wrapper() {
|
|
27
|
+
return this._elements.wrapper;
|
|
28
|
+
}
|
|
29
|
+
/** `scrollLeft` target value */
|
|
30
|
+
get targetLeft() {
|
|
31
|
+
return this._targetLeft;
|
|
32
|
+
}
|
|
33
|
+
set targetLeft(value) {
|
|
34
|
+
this.setTargetLeft(value);
|
|
35
|
+
this._enable();
|
|
36
|
+
}
|
|
37
|
+
/** Update `targetLeft` without animation */
|
|
38
|
+
setTargetLeft(value) {
|
|
39
|
+
this._targetLeft = clamp(value, [0, this.maxScrollableWidth]);
|
|
40
|
+
}
|
|
41
|
+
/** `scrollTop` target value */
|
|
42
|
+
get targetTop() {
|
|
43
|
+
return this._targetTop;
|
|
44
|
+
}
|
|
45
|
+
set targetTop(value) {
|
|
46
|
+
this.setTargetTop(value);
|
|
47
|
+
this._enable();
|
|
48
|
+
}
|
|
49
|
+
/** Update `targetTop` without animation */
|
|
50
|
+
setTargetTop(value) {
|
|
51
|
+
this._targetTop = clamp(value, [0, this.maxScrollableHeight]);
|
|
52
|
+
}
|
|
53
|
+
/** `scrollLeft` */
|
|
54
|
+
get scrollLeft() {
|
|
55
|
+
return this._scrollLeft;
|
|
56
|
+
}
|
|
57
|
+
set scrollLeft(value) {
|
|
58
|
+
this.setTargetLeft(value);
|
|
59
|
+
this._scrollLeft = this._targetLeft;
|
|
60
|
+
this._enable();
|
|
61
|
+
}
|
|
62
|
+
/** `scrollTop` */
|
|
63
|
+
get scrollTop() {
|
|
64
|
+
return this._scrollTop;
|
|
65
|
+
}
|
|
66
|
+
set scrollTop(value) {
|
|
67
|
+
this.setTargetTop(value);
|
|
68
|
+
this._scrollTop = this._targetTop;
|
|
69
|
+
this._enable();
|
|
70
|
+
}
|
|
71
|
+
/** Scroll width */
|
|
72
|
+
get scrollWidth() {
|
|
73
|
+
return this._scrollWidth;
|
|
74
|
+
}
|
|
75
|
+
/** Scroll height */
|
|
76
|
+
get scrollHeight() {
|
|
77
|
+
return this._scrollHeight;
|
|
78
|
+
}
|
|
79
|
+
/** Container width */
|
|
80
|
+
get clientWidth() {
|
|
81
|
+
return this._clientWidth;
|
|
82
|
+
}
|
|
83
|
+
/** Container height */
|
|
84
|
+
get clientHeight() {
|
|
85
|
+
return this._clientHeight;
|
|
86
|
+
}
|
|
87
|
+
/** Maximum scrollable area of the X axis */
|
|
88
|
+
get maxScrollableWidth() {
|
|
89
|
+
return this.scrollWidth - this.clientWidth;
|
|
90
|
+
}
|
|
91
|
+
/** Maximum scrollable area of the Y axis */
|
|
92
|
+
get maxScrollableHeight() {
|
|
93
|
+
return this.scrollHeight - this.clientHeight;
|
|
94
|
+
}
|
|
95
|
+
/** Has scroll */
|
|
96
|
+
get hasScroll() {
|
|
97
|
+
return this.maxScrollableHeight > 0 || this.maxScrollableWidth > 0;
|
|
98
|
+
}
|
|
99
|
+
get isSmoothScroll() {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
constructor(initialProps, canInit = true) {
|
|
103
|
+
super(initialProps, false);
|
|
42
104
|
// set default variables
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
this._targetLeft = 0;
|
|
106
|
+
this._targetTop = 0;
|
|
107
|
+
this._scrollLeft = 0;
|
|
108
|
+
this._scrollTop = 0;
|
|
109
|
+
this._scrollWidth = 0;
|
|
110
|
+
this._scrollHeight = 0;
|
|
111
|
+
this._clientWidth = 0;
|
|
112
|
+
this._clientHeight = 0;
|
|
113
|
+
this._wrapperWidth = 0;
|
|
114
|
+
this._wrapperHeight = 0;
|
|
115
|
+
this._frameIndex = 0;
|
|
116
|
+
this._isEqualLerp = false;
|
|
117
|
+
const { container, elements, hasWillChange, animationFrame, translatePrecision, } = this.props;
|
|
56
118
|
// get outer elements
|
|
57
|
-
|
|
58
|
-
if (!(
|
|
59
|
-
throw new Error(
|
|
119
|
+
this._container = selectOne(container);
|
|
120
|
+
if (!(this._container instanceof HTMLElement)) {
|
|
121
|
+
throw new Error(`${container} is not a HTMLElement`);
|
|
60
122
|
}
|
|
61
|
-
|
|
123
|
+
this.toggleClassName(this._container, this.className(''), true);
|
|
62
124
|
// create elements
|
|
63
|
-
|
|
64
|
-
container:
|
|
65
|
-
wrapperClassName:
|
|
66
|
-
elements
|
|
67
|
-
hasWillChange
|
|
68
|
-
translatePrecision
|
|
125
|
+
this._elements = new Elements({
|
|
126
|
+
container: this._container,
|
|
127
|
+
wrapperClassName: this.className('__wrapper'),
|
|
128
|
+
elements,
|
|
129
|
+
hasWillChange,
|
|
130
|
+
translatePrecision,
|
|
69
131
|
});
|
|
70
132
|
// set classnames
|
|
71
|
-
|
|
133
|
+
this._setDirectionClassNames(true);
|
|
72
134
|
// create animation frame
|
|
73
|
-
|
|
74
|
-
callback:
|
|
135
|
+
this._animationFrame = new AnimationFrame({
|
|
136
|
+
callback: () => this.render(),
|
|
75
137
|
outerAnimationFrame: animationFrame,
|
|
76
138
|
});
|
|
77
139
|
// initialize the class
|
|
78
140
|
if (canInit) {
|
|
79
|
-
|
|
141
|
+
this.init();
|
|
80
142
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return __assign(__assign({}, _super.prototype._getDefaultProps.call(this)), { container: "#".concat(this.prefix), elements: false, animationFrame: false, viewportTarget: 'any', resizeDebounce: 0, hasWillChange: true, translatePrecision: 2, isEnabled: true, hasWheel: true, direction: 'vertical', isInverseHandlerDirection: false, isAutoStop: true, hasStopPropagation: true, lerp: 0.1, isFpsNormalized: true, lerpApproximation: 0.1 });
|
|
85
|
-
};
|
|
86
|
-
Object.defineProperty(SmoothScroll.prototype, "prefix", {
|
|
87
|
-
get: function () {
|
|
88
|
-
return "".concat(this.app.prefix, "smooth-scroll");
|
|
89
|
-
},
|
|
90
|
-
enumerable: false,
|
|
91
|
-
configurable: true
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(SmoothScroll.prototype, "container", {
|
|
94
|
-
/** Scroll container */
|
|
95
|
-
get: function () {
|
|
96
|
-
return this._container;
|
|
97
|
-
},
|
|
98
|
-
enumerable: false,
|
|
99
|
-
configurable: true
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(SmoothScroll.prototype, "wrapper", {
|
|
102
|
-
/**
|
|
103
|
-
* Scroll wrapper. If the element does not exist indide the `container`,
|
|
104
|
-
* it will be created automatically
|
|
105
|
-
*/
|
|
106
|
-
get: function () {
|
|
107
|
-
return this._elements.wrapper;
|
|
108
|
-
},
|
|
109
|
-
enumerable: false,
|
|
110
|
-
configurable: true
|
|
111
|
-
});
|
|
112
|
-
Object.defineProperty(SmoothScroll.prototype, "targetLeft", {
|
|
113
|
-
/** `scrollLeft` target value */
|
|
114
|
-
get: function () {
|
|
115
|
-
return this._targetLeft;
|
|
116
|
-
},
|
|
117
|
-
set: function (value) {
|
|
118
|
-
this.setTargetLeft(value);
|
|
119
|
-
this._enable();
|
|
120
|
-
},
|
|
121
|
-
enumerable: false,
|
|
122
|
-
configurable: true
|
|
123
|
-
});
|
|
124
|
-
/** Update `targetLeft` without animation */
|
|
125
|
-
SmoothScroll.prototype.setTargetLeft = function (value) {
|
|
126
|
-
this._targetLeft = clamp(value, [0, this.maxScrollableWidth]);
|
|
127
|
-
};
|
|
128
|
-
Object.defineProperty(SmoothScroll.prototype, "targetTop", {
|
|
129
|
-
/** `scrollTop` target value */
|
|
130
|
-
get: function () {
|
|
131
|
-
return this._targetTop;
|
|
132
|
-
},
|
|
133
|
-
set: function (value) {
|
|
134
|
-
this.setTargetTop(value);
|
|
135
|
-
this._enable();
|
|
136
|
-
},
|
|
137
|
-
enumerable: false,
|
|
138
|
-
configurable: true
|
|
139
|
-
});
|
|
140
|
-
/** Update `targetTop` without animation */
|
|
141
|
-
SmoothScroll.prototype.setTargetTop = function (value) {
|
|
142
|
-
this._targetTop = clamp(value, [0, this.maxScrollableHeight]);
|
|
143
|
-
};
|
|
144
|
-
Object.defineProperty(SmoothScroll.prototype, "scrollLeft", {
|
|
145
|
-
/** `scrollLeft` */
|
|
146
|
-
get: function () {
|
|
147
|
-
return this._scrollLeft;
|
|
148
|
-
},
|
|
149
|
-
set: function (value) {
|
|
150
|
-
this.setTargetLeft(value);
|
|
151
|
-
this._scrollLeft = this._targetLeft;
|
|
152
|
-
this._enable();
|
|
153
|
-
},
|
|
154
|
-
enumerable: false,
|
|
155
|
-
configurable: true
|
|
156
|
-
});
|
|
157
|
-
Object.defineProperty(SmoothScroll.prototype, "scrollTop", {
|
|
158
|
-
/** `scrollTop` */
|
|
159
|
-
get: function () {
|
|
160
|
-
return this._scrollTop;
|
|
161
|
-
},
|
|
162
|
-
set: function (value) {
|
|
163
|
-
this.setTargetTop(value);
|
|
164
|
-
this._scrollTop = this._targetTop;
|
|
165
|
-
this._enable();
|
|
166
|
-
},
|
|
167
|
-
enumerable: false,
|
|
168
|
-
configurable: true
|
|
169
|
-
});
|
|
170
|
-
Object.defineProperty(SmoothScroll.prototype, "scrollWidth", {
|
|
171
|
-
/** Scroll width */
|
|
172
|
-
get: function () {
|
|
173
|
-
return this._scrollWidth;
|
|
174
|
-
},
|
|
175
|
-
enumerable: false,
|
|
176
|
-
configurable: true
|
|
177
|
-
});
|
|
178
|
-
Object.defineProperty(SmoothScroll.prototype, "scrollHeight", {
|
|
179
|
-
/** Scroll height */
|
|
180
|
-
get: function () {
|
|
181
|
-
return this._scrollHeight;
|
|
182
|
-
},
|
|
183
|
-
enumerable: false,
|
|
184
|
-
configurable: true
|
|
185
|
-
});
|
|
186
|
-
Object.defineProperty(SmoothScroll.prototype, "clientWidth", {
|
|
187
|
-
/** Container width */
|
|
188
|
-
get: function () {
|
|
189
|
-
return this._clientWidth;
|
|
190
|
-
},
|
|
191
|
-
enumerable: false,
|
|
192
|
-
configurable: true
|
|
193
|
-
});
|
|
194
|
-
Object.defineProperty(SmoothScroll.prototype, "clientHeight", {
|
|
195
|
-
/** Container height */
|
|
196
|
-
get: function () {
|
|
197
|
-
return this._clientHeight;
|
|
198
|
-
},
|
|
199
|
-
enumerable: false,
|
|
200
|
-
configurable: true
|
|
201
|
-
});
|
|
202
|
-
Object.defineProperty(SmoothScroll.prototype, "maxScrollableWidth", {
|
|
203
|
-
/** Maximum scrollable area of the X axis */
|
|
204
|
-
get: function () {
|
|
205
|
-
return this.scrollWidth - this.clientWidth;
|
|
206
|
-
},
|
|
207
|
-
enumerable: false,
|
|
208
|
-
configurable: true
|
|
209
|
-
});
|
|
210
|
-
Object.defineProperty(SmoothScroll.prototype, "maxScrollableHeight", {
|
|
211
|
-
/** Maximum scrollable area of the Y axis */
|
|
212
|
-
get: function () {
|
|
213
|
-
return this.scrollHeight - this.clientHeight;
|
|
214
|
-
},
|
|
215
|
-
enumerable: false,
|
|
216
|
-
configurable: true
|
|
217
|
-
});
|
|
218
|
-
Object.defineProperty(SmoothScroll.prototype, "hasScroll", {
|
|
219
|
-
/** Has scroll */
|
|
220
|
-
get: function () {
|
|
221
|
-
return this.maxScrollableHeight > 0 || this.maxScrollableWidth > 0;
|
|
222
|
-
},
|
|
223
|
-
enumerable: false,
|
|
224
|
-
configurable: true
|
|
225
|
-
});
|
|
226
|
-
Object.defineProperty(SmoothScroll.prototype, "isSmoothScroll", {
|
|
227
|
-
get: function () {
|
|
228
|
-
return true;
|
|
229
|
-
},
|
|
230
|
-
enumerable: false,
|
|
231
|
-
configurable: true
|
|
232
|
-
});
|
|
233
|
-
SmoothScroll.prototype._init = function () {
|
|
234
|
-
_super.prototype._init.call(this);
|
|
143
|
+
}
|
|
144
|
+
_init() {
|
|
145
|
+
super._init();
|
|
235
146
|
this._setEvents();
|
|
236
147
|
this._toggle();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
148
|
+
}
|
|
149
|
+
_setDirectionClassNames(isActive) {
|
|
150
|
+
const { direction } = this.props;
|
|
151
|
+
const isHorizontal = direction === 'horizontal' && isActive;
|
|
152
|
+
const isVertical = direction === 'vertical' && isActive;
|
|
242
153
|
this.wrapper.classList.toggle(this.className('_horizontal'), isHorizontal);
|
|
243
154
|
this.wrapper.classList.toggle(this.className('_vertical'), isVertical);
|
|
244
|
-
}
|
|
155
|
+
}
|
|
245
156
|
/** Set events */
|
|
246
|
-
|
|
247
|
-
var _this = this;
|
|
157
|
+
_setEvents() {
|
|
248
158
|
this._setResize();
|
|
249
159
|
// wheel
|
|
250
|
-
this.addEventListener(this.container, 'wheel',
|
|
251
|
-
return _this.handleWheel(event);
|
|
252
|
-
});
|
|
160
|
+
this.addEventListener(this.container, 'wheel', (event) => this.handleWheel(event));
|
|
253
161
|
// prevent native scroll
|
|
254
|
-
this.addEventListener(this.container, 'scroll',
|
|
255
|
-
|
|
256
|
-
|
|
162
|
+
this.addEventListener(this.container, 'scroll', () => {
|
|
163
|
+
this.container.scrollTop = 0;
|
|
164
|
+
this.container.scrollLeft = 0;
|
|
257
165
|
});
|
|
258
|
-
}
|
|
166
|
+
}
|
|
259
167
|
/** Set resize events */
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
var _a = this.props, viewportTarget = _a.viewportTarget, resizeDebounce = _a.resizeDebounce;
|
|
168
|
+
_setResize() {
|
|
169
|
+
const { viewportTarget, resizeDebounce } = this.props;
|
|
263
170
|
// resize handler
|
|
264
|
-
|
|
265
|
-
onResize:
|
|
171
|
+
const resizeHandler = onResize({
|
|
172
|
+
onResize: () => this.resize(true),
|
|
266
173
|
element: [this.container, this.wrapper],
|
|
267
|
-
viewportTarget
|
|
268
|
-
resizeDebounce
|
|
174
|
+
viewportTarget,
|
|
175
|
+
resizeDebounce,
|
|
269
176
|
});
|
|
270
|
-
this.addDestroyableAction(
|
|
177
|
+
this.addDestroyableAction(() => resizeHandler.remove());
|
|
271
178
|
// initial resize
|
|
272
179
|
resizeHandler.resize();
|
|
273
180
|
// if resize observer not used, we recalculate sizes on each 10th frame
|
|
274
181
|
if (!resizeHandler.hasResizeObserver) {
|
|
275
|
-
this.addCallback('render', (
|
|
276
|
-
if (
|
|
277
|
-
|
|
182
|
+
this.addCallback('render', (() => {
|
|
183
|
+
if (this._frameIndex % 10 === 0) {
|
|
184
|
+
this._recalculateScrollSizes();
|
|
278
185
|
}
|
|
279
186
|
}), { isProtected: true, name: this.name });
|
|
280
187
|
}
|
|
281
|
-
}
|
|
188
|
+
}
|
|
282
189
|
/** Handle properties mutation */
|
|
283
|
-
|
|
284
|
-
|
|
190
|
+
_onPropsMutate() {
|
|
191
|
+
super._onPropsMutate();
|
|
285
192
|
this._setDirectionClassNames(true);
|
|
286
193
|
this.resize();
|
|
287
194
|
this._toggle();
|
|
288
|
-
}
|
|
195
|
+
}
|
|
289
196
|
/** Recalculate scroll sizes */
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
197
|
+
_recalculateScrollSizes() {
|
|
198
|
+
const { wrapper } = this;
|
|
199
|
+
const height = wrapper.clientHeight;
|
|
200
|
+
const width = wrapper.clientWidth;
|
|
294
201
|
if (height !== this._wrapperHeight || width !== this._wrapperWidth) {
|
|
295
202
|
this.resize(false);
|
|
296
203
|
}
|
|
297
|
-
}
|
|
204
|
+
}
|
|
298
205
|
/** Resize the scene */
|
|
299
|
-
|
|
300
|
-
if (isNative === void 0) { isNative = false; }
|
|
206
|
+
resize(isNative = false) {
|
|
301
207
|
this._resize(isNative);
|
|
302
208
|
// launch callbacks
|
|
303
209
|
this.callbacks.tbt('resize', undefined);
|
|
304
210
|
// enable animation
|
|
305
211
|
this._enable();
|
|
306
|
-
}
|
|
212
|
+
}
|
|
307
213
|
/** Resize the scene */
|
|
308
|
-
|
|
214
|
+
_resize(
|
|
309
215
|
/** If the method was called natively on window resize */
|
|
310
|
-
isNative) {
|
|
311
|
-
|
|
312
|
-
var _a = this, container = _a.container, wrapper = _a.wrapper;
|
|
216
|
+
isNative = false) {
|
|
217
|
+
const { container, wrapper } = this;
|
|
313
218
|
this._clientWidth = container.clientWidth;
|
|
314
219
|
this._clientHeight = container.clientHeight;
|
|
315
220
|
this._wrapperWidth = wrapper.clientWidth;
|
|
@@ -336,14 +241,14 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
336
241
|
container.classList.toggle(this.className('_no-scroll'), !this.hasScroll);
|
|
337
242
|
// update elements
|
|
338
243
|
this._elements.updateElementsProp(this.scrollLeft, this.scrollTop);
|
|
339
|
-
}
|
|
244
|
+
}
|
|
340
245
|
/** Event on wheel */
|
|
341
|
-
|
|
342
|
-
|
|
246
|
+
handleWheel(event) {
|
|
247
|
+
const { isEnabled, hasWheel, hasStopPropagation, isInverseHandlerDirection, } = this.props;
|
|
343
248
|
if (!isEnabled || !hasWheel || !this.hasScroll) {
|
|
344
249
|
return;
|
|
345
250
|
}
|
|
346
|
-
|
|
251
|
+
const isPropagationStopped = hasStopPropagation ||
|
|
347
252
|
(this.scrollTop > 0 && this.scrollTop < this.maxScrollableHeight) ||
|
|
348
253
|
(this.scrollLeft > 0 && this.scrollLeft < this.maxScrollableWidth);
|
|
349
254
|
if (isPropagationStopped) {
|
|
@@ -352,39 +257,39 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
352
257
|
event.preventDefault();
|
|
353
258
|
}
|
|
354
259
|
// get normalized delta
|
|
355
|
-
|
|
260
|
+
const { pixelX, pixelY } = normalizeWheel(event);
|
|
356
261
|
// set new scroll targets
|
|
357
|
-
|
|
358
|
-
|
|
262
|
+
const leftIterator = isInverseHandlerDirection ? pixelY : pixelX;
|
|
263
|
+
const topIterator = isInverseHandlerDirection ? pixelX : pixelY;
|
|
359
264
|
this.setTargetLeft(this.targetLeft + leftIterator);
|
|
360
265
|
this.setTargetTop(this.targetTop + topIterator);
|
|
361
266
|
// play animation frame
|
|
362
267
|
this._enable();
|
|
363
268
|
// launch events
|
|
364
|
-
this.callbacks.tbt('wheel', { event
|
|
365
|
-
}
|
|
269
|
+
this.callbacks.tbt('wheel', { event });
|
|
270
|
+
}
|
|
366
271
|
/** Toggle animation: Enable / Disable scrolling */
|
|
367
|
-
|
|
272
|
+
_toggle() {
|
|
368
273
|
if (this.props.isEnabled) {
|
|
369
274
|
this._enable();
|
|
370
275
|
}
|
|
371
276
|
else {
|
|
372
277
|
this._disable();
|
|
373
278
|
}
|
|
374
|
-
}
|
|
279
|
+
}
|
|
375
280
|
/** Enable scrolling */
|
|
376
|
-
|
|
281
|
+
_enable() {
|
|
377
282
|
if (!this.props.isEnabled) {
|
|
378
283
|
return;
|
|
379
284
|
}
|
|
380
285
|
this._animationFrame.enable();
|
|
381
|
-
}
|
|
286
|
+
}
|
|
382
287
|
/** Disable scrolling */
|
|
383
|
-
|
|
288
|
+
_disable() {
|
|
384
289
|
this._animationFrame.disable();
|
|
385
|
-
}
|
|
290
|
+
}
|
|
386
291
|
/** Render elements */
|
|
387
|
-
|
|
292
|
+
render() {
|
|
388
293
|
this._frameIndex += 1;
|
|
389
294
|
this._calcScrollValues();
|
|
390
295
|
this._calcElementsValues();
|
|
@@ -399,58 +304,56 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
399
304
|
this.callbacks.tbt('render', undefined);
|
|
400
305
|
// auto stop
|
|
401
306
|
this._checkAutoStop();
|
|
402
|
-
}
|
|
307
|
+
}
|
|
403
308
|
/** Calculate scroll values */
|
|
404
|
-
|
|
309
|
+
_calcScrollValues() {
|
|
405
310
|
this._scrollLeft = this._lerp(this.scrollLeft, this.targetLeft);
|
|
406
311
|
this._scrollTop = this._lerp(this.scrollTop, this.targetTop);
|
|
407
|
-
}
|
|
312
|
+
}
|
|
408
313
|
/** Calculate elements' values */
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
for (
|
|
412
|
-
|
|
413
|
-
|
|
314
|
+
_calcElementsValues() {
|
|
315
|
+
const { elements } = this._elements;
|
|
316
|
+
for (let index = 0; index < elements.length; index += 1) {
|
|
317
|
+
const element = elements[index];
|
|
318
|
+
const elementLerp = this._getLerp(element);
|
|
414
319
|
element.smoothScrollLeft = this._lerp(element.smoothScrollLeft, this._targetLeft, elementLerp);
|
|
415
320
|
element.smoothScrollTop = this._lerp(element.smoothScrollTop, this._targetTop, elementLerp);
|
|
416
321
|
}
|
|
417
|
-
}
|
|
322
|
+
}
|
|
418
323
|
/** Make auto stop if the target and current values are equal */
|
|
419
|
-
|
|
324
|
+
_checkAutoStop() {
|
|
420
325
|
if (!this.props.isAutoStop) {
|
|
421
326
|
return;
|
|
422
327
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
328
|
+
const yDiff = Math.abs(this.targetTop - this.scrollTop);
|
|
329
|
+
const xDiff = Math.abs(this.targetLeft - this.scrollLeft);
|
|
330
|
+
const isGlobalInterpolated = xDiff === 0 && yDiff === 0;
|
|
331
|
+
const isInnerInterpolated = this._elements.checkAllScrollValuesEqual();
|
|
427
332
|
if (isGlobalInterpolated && isInnerInterpolated) {
|
|
428
333
|
this._disable();
|
|
429
334
|
}
|
|
430
|
-
}
|
|
335
|
+
}
|
|
431
336
|
/** Interpolate values */
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
var value = lerp(current, target, currentEase, lerpApproximation);
|
|
337
|
+
_lerp(current, target, ease = this._getLerp()) {
|
|
338
|
+
const { lerpApproximation } = this.props;
|
|
339
|
+
const currentEase = this._isInstant ? 1 : ease;
|
|
340
|
+
const value = lerp(current, target, currentEase, lerpApproximation);
|
|
437
341
|
return value;
|
|
438
|
-
}
|
|
342
|
+
}
|
|
439
343
|
/** Get lerp */
|
|
440
|
-
|
|
344
|
+
_getLerp(element) {
|
|
441
345
|
var _a;
|
|
442
|
-
|
|
443
|
-
|
|
346
|
+
const { lerp: lerpEase, isFpsNormalized } = this.props;
|
|
347
|
+
const fpsMultiplier = isFpsNormalized
|
|
444
348
|
? this._animationFrame.easeMultiplier
|
|
445
349
|
: 1;
|
|
446
350
|
if (this._isEqualLerp || !element) {
|
|
447
351
|
return lerpEase * fpsMultiplier;
|
|
448
352
|
}
|
|
449
353
|
return ((_a = element.smoothScrollLerp) !== null && _a !== void 0 ? _a : lerpEase) * fpsMultiplier;
|
|
450
|
-
}
|
|
354
|
+
}
|
|
451
355
|
/** Scroll to */
|
|
452
|
-
|
|
453
|
-
var top = _a.top, left = _a.left, behavior = _a.behavior;
|
|
356
|
+
scrollTo({ top, left, behavior }) {
|
|
454
357
|
if (typeof left !== 'undefined') {
|
|
455
358
|
if (behavior === 'smooth') {
|
|
456
359
|
this.setTargetLeft(left);
|
|
@@ -472,18 +375,16 @@ var SmoothScroll = /** @class */ (function (_super) {
|
|
|
472
375
|
if (behavior === 'smooth') {
|
|
473
376
|
this._enable();
|
|
474
377
|
}
|
|
475
|
-
}
|
|
378
|
+
}
|
|
476
379
|
/** Destroy the module */
|
|
477
|
-
|
|
478
|
-
|
|
380
|
+
_destroy() {
|
|
381
|
+
super._destroy();
|
|
479
382
|
this._disable();
|
|
480
383
|
this._elements.destroy();
|
|
481
384
|
this._animationFrame.destroy();
|
|
482
385
|
this._setDirectionClassNames(false);
|
|
483
386
|
this._container.classList.remove(this.className('_has-scroll'));
|
|
484
387
|
this._container.classList.remove(this.className('_no-scroll'));
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
}(ComponentClass));
|
|
488
|
-
export { SmoothScroll };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
489
390
|
//# sourceMappingURL=index.js.map
|