vevet 2.3.0 → 2.5.1

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.
Files changed (42) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/components/scroll/section/ScrollSectionProgress.js +261 -0
  3. package/build/cjs/index.js +5 -1
  4. package/build/cjs/utils/scroll/getScrollValues.js +20 -0
  5. package/build/cjs/utils/scroll/index.js +12 -0
  6. package/build/cjs/utils/scroll/scrollTo.js +41 -0
  7. package/build/cjs/utils/scroll/scrollToElement.js +39 -0
  8. package/build/cjs/utils/scroll/to.js +41 -0
  9. package/build/es/components/scroll/section/ScrollSectionProgress.js +181 -0
  10. package/build/es/index.js +4 -1
  11. package/build/es/utils/scroll/getScrollValues.js +16 -0
  12. package/build/es/utils/scroll/index.js +4 -0
  13. package/build/es/utils/scroll/scrollTo.js +34 -0
  14. package/build/es/utils/scroll/scrollToElement.js +32 -0
  15. package/build/es/utils/scroll/to.js +34 -0
  16. package/build/types/components/scroll/section/ScrollSectionProgress.d.ts +131 -0
  17. package/build/types/components/scroll/section/ScrollSectionProgress.d.ts.map +1 -0
  18. package/build/types/components/scroll/types.d.ts +2 -5
  19. package/build/types/components/scroll/types.d.ts.map +1 -1
  20. package/build/types/index.d.ts +4 -1
  21. package/build/types/index.d.ts.map +1 -1
  22. package/build/types/utils/scroll/getScrollValues.d.ts +9 -0
  23. package/build/types/utils/scroll/getScrollValues.d.ts.map +1 -0
  24. package/build/types/utils/scroll/index.d.ts +5 -0
  25. package/build/types/utils/scroll/index.d.ts.map +1 -0
  26. package/build/types/utils/scroll/scrollTo.d.ts +28 -0
  27. package/build/types/utils/scroll/scrollTo.d.ts.map +1 -0
  28. package/build/types/utils/scroll/scrollToElement.d.ts +32 -0
  29. package/build/types/utils/scroll/scrollToElement.d.ts.map +1 -0
  30. package/build/types/utils/scroll/to.d.ts +28 -0
  31. package/build/types/utils/scroll/to.d.ts.map +1 -0
  32. package/build/types/utils/types/general.d.ts +6 -0
  33. package/build/types/utils/types/general.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/src/ts/components/scroll/section/ScrollSectionProgress.ts +344 -0
  36. package/src/ts/components/scroll/types.ts +3 -5
  37. package/src/ts/index.ts +4 -0
  38. package/src/ts/utils/scroll/getScrollValues.ts +20 -0
  39. package/src/ts/utils/scroll/index.ts +9 -0
  40. package/src/ts/utils/scroll/scrollTo.ts +65 -0
  41. package/src/ts/utils/scroll/scrollToElement.ts +74 -0
  42. package/src/ts/utils/types/general.ts +7 -0
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.ScrollSectionProgress = void 0;
33
+ var vevet_dom_1 = require("vevet-dom");
34
+ var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
35
+ var Component_1 = require("../../../base/Component");
36
+ var clampScope_1 = __importDefault(require("../../../utils/math/clampScope"));
37
+ var getScrollValues_1 = __importDefault(require("../../../utils/scroll/getScrollValues"));
38
+ /**
39
+ * Elements into viewport
40
+ */
41
+ var ScrollSectionProgress = /** @class */ (function (_super) {
42
+ __extends(ScrollSectionProgress, _super);
43
+ function ScrollSectionProgress(initialProp, init) {
44
+ if (init === void 0) { init = true; }
45
+ var _this = _super.call(this, initialProp, false) || this;
46
+ // get scroll container
47
+ if (typeof _this.prop.container === 'string') {
48
+ _this._scrollContainer = (0, vevet_dom_1.selectOne)(_this.prop.container);
49
+ }
50
+ else {
51
+ _this._scrollContainer = _this.prop.container;
52
+ }
53
+ // get section element
54
+ if (typeof _this.prop.section === 'string') {
55
+ _this._section = (0, vevet_dom_1.selectOne)(_this.prop.section);
56
+ }
57
+ else {
58
+ _this._section = _this.prop.section;
59
+ }
60
+ // set defaults
61
+ _this._progress = -0.001;
62
+ _this._scopeScroll = [0, 0];
63
+ _this._scopeIn = [0, 0];
64
+ _this._scopeMove = [0, 0];
65
+ _this._scopeOut = [0, 0];
66
+ // initialize the class
67
+ if (init) {
68
+ _this.init();
69
+ }
70
+ return _this;
71
+ }
72
+ ScrollSectionProgress.prototype._getDefaultProp = function () {
73
+ return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, viewportTarget: '', resizeTimeout: 0 });
74
+ };
75
+ Object.defineProperty(ScrollSectionProgress.prototype, "scrollContainer", {
76
+ get: function () {
77
+ return this._scrollContainer;
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
82
+ Object.defineProperty(ScrollSectionProgress.prototype, "section", {
83
+ get: function () {
84
+ return this._section;
85
+ },
86
+ enumerable: false,
87
+ configurable: true
88
+ });
89
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeScroll", {
90
+ get: function () {
91
+ return this._scopeScroll;
92
+ },
93
+ enumerable: false,
94
+ configurable: true
95
+ });
96
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeIn", {
97
+ get: function () {
98
+ return this._scopeIn;
99
+ },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeMove", {
104
+ get: function () {
105
+ return this._scopeMove;
106
+ },
107
+ enumerable: false,
108
+ configurable: true
109
+ });
110
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeOut", {
111
+ get: function () {
112
+ return this._scopeOut;
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Object.defineProperty(ScrollSectionProgress.prototype, "progress", {
118
+ /**
119
+ * Global progress
120
+ */
121
+ get: function () {
122
+ return this._progress;
123
+ },
124
+ set: function (val) {
125
+ this._progress = val;
126
+ },
127
+ enumerable: false,
128
+ configurable: true
129
+ });
130
+ ScrollSectionProgress.prototype.init = function () {
131
+ _super.prototype.init.call(this);
132
+ };
133
+ // Set Module Events
134
+ ScrollSectionProgress.prototype._setEvents = function () {
135
+ var _this = this;
136
+ _super.prototype._setEvents.call(this);
137
+ // set resize events
138
+ this.addViewportCallback(this.prop.viewportTarget, function () {
139
+ _this.resize();
140
+ }, {
141
+ timeout: this.prop.resizeTimeout,
142
+ });
143
+ // resize on page loaded
144
+ this._loadedEvent = this._app.onPageLoaded();
145
+ this._loadedEvent.then(function () {
146
+ _this.resize();
147
+ }).catch(function () { });
148
+ // set scroll events
149
+ this._scrollEvent = (0, onScroll_1.default)({
150
+ container: this.prop.container,
151
+ callback: this._handleScroll.bind(this),
152
+ });
153
+ };
154
+ ScrollSectionProgress.prototype._onPropMutate = function () {
155
+ _super.prototype._onPropMutate.call(this);
156
+ this.resize();
157
+ };
158
+ Object.defineProperty(ScrollSectionProgress.prototype, "progressIn", {
159
+ /**
160
+ * 'in' progress
161
+ */
162
+ get: function () {
163
+ return (0, clampScope_1.default)(this.progress, this.scopeIn) || 0;
164
+ },
165
+ enumerable: false,
166
+ configurable: true
167
+ });
168
+ Object.defineProperty(ScrollSectionProgress.prototype, "progressOut", {
169
+ /**
170
+ * 'out' progress
171
+ */
172
+ get: function () {
173
+ return (0, clampScope_1.default)(this.progress, this.scopeOut) || 0;
174
+ },
175
+ enumerable: false,
176
+ configurable: true
177
+ });
178
+ Object.defineProperty(ScrollSectionProgress.prototype, "progressMove", {
179
+ /**
180
+ * 'move' progress
181
+ */
182
+ get: function () {
183
+ return (0, clampScope_1.default)(this.progress, this.scopeMove) || 0;
184
+ },
185
+ enumerable: false,
186
+ configurable: true
187
+ });
188
+ /**
189
+ * Handle scroll event
190
+ */
191
+ ScrollSectionProgress.prototype._handleScroll = function () {
192
+ // calculate scopes
193
+ var scrollData = (0, getScrollValues_1.default)(this.scrollContainer);
194
+ if (!scrollData) {
195
+ return;
196
+ }
197
+ this._render(scrollData);
198
+ };
199
+ /**
200
+ * Resize the scene
201
+ */
202
+ ScrollSectionProgress.prototype.resize = function () {
203
+ // calculate scopes
204
+ var scrollData = (0, getScrollValues_1.default)(this.scrollContainer);
205
+ if (!scrollData) {
206
+ return;
207
+ }
208
+ // get sizes
209
+ var bounding = this.section.getBoundingClientRect();
210
+ var vHeight = this._app.viewport.height;
211
+ // calculate scroll scope
212
+ var inStart = scrollData.scrollTop + bounding.top - vHeight;
213
+ var moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
214
+ var scrollLine = moveEnd - inStart;
215
+ this._scopeScroll = [inStart, moveEnd];
216
+ // calculate scopes
217
+ this._scopeIn = [0, vHeight / scrollLine];
218
+ this._scopeOut = [1 - vHeight / scrollLine, 1];
219
+ this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
220
+ // launch callbacks
221
+ this.callbacks.tbt('resize', false);
222
+ // render the scene
223
+ this._render(scrollData, true);
224
+ };
225
+ /**
226
+ * Render the scene
227
+ */
228
+ ScrollSectionProgress.prototype._render = function (scrollData, force) {
229
+ if (force === void 0) { force = false; }
230
+ var canRender = this._canRender(scrollData, force);
231
+ if (!canRender) {
232
+ return;
233
+ }
234
+ this.callbacks.tbt('render', false);
235
+ };
236
+ /**
237
+ * Check if the section can be rendered
238
+ */
239
+ ScrollSectionProgress.prototype._canRender = function (scrollData, force) {
240
+ if (force === void 0) { force = false; }
241
+ if (!scrollData) {
242
+ return false;
243
+ }
244
+ var scrollTop = scrollData.scrollTop;
245
+ var prevProgress = this.progress;
246
+ var progress = (0, clampScope_1.default)(scrollTop, [this._scopeScroll[0], this._scopeScroll[1]]) || 0;
247
+ this.progress = progress;
248
+ return force || (progress !== prevProgress);
249
+ };
250
+ /**
251
+ * Destroy the module
252
+ */
253
+ ScrollSectionProgress.prototype._destroy = function () {
254
+ var _a, _b;
255
+ _super.prototype._destroy.call(this);
256
+ (_a = this._scrollEvent) === null || _a === void 0 ? void 0 : _a.remove();
257
+ (_b = this._loadedEvent) === null || _b === void 0 ? void 0 : _b.cancel();
258
+ };
259
+ return ScrollSectionProgress;
260
+ }(Component_1.Component));
261
+ exports.ScrollSectionProgress = ScrollSectionProgress;
@@ -19,10 +19,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.CustomCursor = exports.SplitText = exports.SmoothScrollDragPlugin = exports.SmoothScrollKeyboardPlugin = exports.ScrollView = exports.ScrollEventsBase = exports.ScrollBar = exports.SmoothScroll = exports.Ctx2DPrerender = exports.Ctx2D = exports.DraggerDirection = exports.DraggerMove = exports.Dragger = exports.ProgressPreloader = exports.Preloader = exports.Timeline = exports.StaticTimeline = exports.AnimationFrame = exports.WheelHandler = exports.Page = exports.Plugin = exports.Component = exports.Module = exports.MutableProp = exports.Callbacks = exports.PageLoad = exports.Viewport = exports.Application = exports.GeneralTypes = exports.utils = void 0;
22
+ exports.CustomCursor = exports.SplitText = exports.ScrollSectionProgress = exports.SmoothScrollDragPlugin = exports.SmoothScrollKeyboardPlugin = exports.ScrollView = exports.ScrollEventsBase = exports.ScrollBar = exports.SmoothScroll = exports.Ctx2DPrerender = exports.Ctx2D = exports.DraggerDirection = exports.DraggerMove = exports.Dragger = exports.ProgressPreloader = exports.Preloader = exports.Timeline = exports.StaticTimeline = exports.AnimationFrame = exports.WheelHandler = exports.Page = exports.Plugin = exports.Component = exports.Module = exports.MutableProp = exports.Callbacks = exports.PageLoad = exports.Viewport = exports.Application = exports.GeneralTypes = exports.utils = void 0;
23
23
  var common = __importStar(require("./utils/common"));
24
24
  var listeners = __importStar(require("./utils/listeners"));
25
25
  var math = __importStar(require("./utils/math"));
26
+ var scroll = __importStar(require("./utils/scroll"));
26
27
  var GeneralTypes = __importStar(require("./utils/types/general"));
27
28
  exports.GeneralTypes = GeneralTypes;
28
29
  var Application_1 = require("./app/Application");
@@ -77,6 +78,8 @@ var SmoothScrollKeyboardPlugin_1 = require("./components/scroll/plugins/SmoothSc
77
78
  Object.defineProperty(exports, "SmoothScrollKeyboardPlugin", { enumerable: true, get: function () { return SmoothScrollKeyboardPlugin_1.SmoothScrollKeyboardPlugin; } });
78
79
  var SmoothScrollDragPlugin_1 = require("./components/scroll/plugins/SmoothScrollDragPlugin");
79
80
  Object.defineProperty(exports, "SmoothScrollDragPlugin", { enumerable: true, get: function () { return SmoothScrollDragPlugin_1.SmoothScrollDragPlugin; } });
81
+ var ScrollSectionProgress_1 = require("./components/scroll/section/ScrollSectionProgress");
82
+ Object.defineProperty(exports, "ScrollSectionProgress", { enumerable: true, get: function () { return ScrollSectionProgress_1.ScrollSectionProgress; } });
80
83
  var SplitText_1 = require("./components/text/SplitText");
81
84
  Object.defineProperty(exports, "SplitText", { enumerable: true, get: function () { return SplitText_1.SplitText; } });
82
85
  var CustomCursor_1 = require("./components/cursor/CustomCursor");
@@ -85,5 +88,6 @@ var utils = {
85
88
  common: common,
86
89
  listeners: listeners,
87
90
  math: math,
91
+ scroll: scroll,
88
92
  };
89
93
  exports.utils = utils;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Get scroll values of a certain element
5
+ */
6
+ function getScrollValues(selector) {
7
+ if (selector === void 0) { selector = window; }
8
+ if (selector) {
9
+ var scrollTop = selector instanceof Window
10
+ ? selector.pageYOffset : selector.scrollTop;
11
+ var scrollLeft = selector instanceof Window
12
+ ? selector.pageXOffset : selector.scrollLeft;
13
+ return {
14
+ scrollTop: scrollTop,
15
+ scrollLeft: scrollLeft,
16
+ };
17
+ }
18
+ return undefined;
19
+ }
20
+ exports.default = getScrollValues;
@@ -0,0 +1,12 @@
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
+ exports.toElement = exports.to = exports.getValues = void 0;
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ exports.getValues = getScrollValues_1.default;
9
+ var scrollTo_1 = __importDefault(require("./scrollTo"));
10
+ exports.to = scrollTo_1.default;
11
+ var scrollToElement_1 = __importDefault(require("./scrollToElement"));
12
+ exports.toElement = scrollToElement_1.default;
@@ -0,0 +1,41 @@
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 Timeline_1 = require("../../components/timeline/Timeline");
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ /**
9
+ * Scroll to coordinates
10
+ */
11
+ function scrollTo(_a) {
12
+ var _b = _a.container, container = _b === void 0 ? window : _b, _c = _a.top, top = _c === void 0 ? 0 : _c, _d = _a.left, left = _d === void 0 ? 0 : _d, _e = _a.duration, duration = _e === void 0 ? 250 : _e;
13
+ return new Promise(function (resolve, reject) {
14
+ // save start values
15
+ var startValues = (0, getScrollValues_1.default)(container);
16
+ if (startValues) {
17
+ // create animation
18
+ var timeline = new Timeline_1.Timeline({
19
+ duration: duration,
20
+ });
21
+ timeline.addCallback('progress', function (data) {
22
+ if (container) {
23
+ container.scrollTo({
24
+ top: startValues.scrollTop
25
+ + (top - startValues.scrollTop) * data.easing,
26
+ left: startValues.scrollLeft
27
+ + (left - startValues.scrollLeft) * data.easing,
28
+ behavior: 'auto',
29
+ });
30
+ }
31
+ });
32
+ timeline.addCallback('end', function () {
33
+ resolve();
34
+ });
35
+ timeline.play();
36
+ return;
37
+ }
38
+ reject();
39
+ });
40
+ }
41
+ exports.default = scrollTo;
@@ -0,0 +1,39 @@
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 vevet_dom_1 = require("vevet-dom");
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ var clamp_1 = __importDefault(require("../math/clamp"));
9
+ var scrollTo_1 = __importDefault(require("./scrollTo"));
10
+ /**
11
+ * Scroll to element
12
+ */
13
+ function scrollToElement(_a) {
14
+ var _b = _a.container, container = _b === void 0 ? window : _b, el = _a.el, _c = _a.top, top = _c === void 0 ? 0 : _c, _d = _a.left, left = _d === void 0 ? 0 : _d, _e = _a.duration, duration = _e === void 0 ? 250 : _e;
15
+ return new Promise(function (resolve, reject) {
16
+ var startValues = (0, getScrollValues_1.default)(container);
17
+ if (startValues) {
18
+ var element = (0, vevet_dom_1.selectOne)(el);
19
+ if (element) {
20
+ var bounding = element.getBoundingClientRect();
21
+ var toTop = (0, clamp_1.default)(bounding.top + startValues.scrollTop - top, [0, Infinity]);
22
+ var toLeft = (0, clamp_1.default)(bounding.left + startValues.scrollLeft - left, [0, Infinity]);
23
+ (0, scrollTo_1.default)({
24
+ container: container,
25
+ top: toTop,
26
+ left: toLeft,
27
+ duration: duration,
28
+ }).then(function () {
29
+ resolve();
30
+ }).catch(function () {
31
+ reject();
32
+ });
33
+ }
34
+ return;
35
+ }
36
+ reject();
37
+ });
38
+ }
39
+ exports.default = scrollToElement;
@@ -0,0 +1,41 @@
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 Timeline_1 = require("../../components/timeline/Timeline");
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ /**
9
+ * Scroll to coordinates
10
+ */
11
+ function scrollTo(_a) {
12
+ var _b = _a.container, container = _b === void 0 ? window : _b, _c = _a.top, top = _c === void 0 ? 0 : _c, _d = _a.left, left = _d === void 0 ? 0 : _d, _e = _a.duration, duration = _e === void 0 ? 250 : _e;
13
+ return new Promise(function (resolve, reject) {
14
+ // save start values
15
+ var startValues = (0, getScrollValues_1.default)(container);
16
+ if (startValues) {
17
+ // create animation
18
+ var timeline = new Timeline_1.Timeline({
19
+ duration: duration,
20
+ });
21
+ timeline.addCallback('progress', function (data) {
22
+ if (container) {
23
+ container.scrollTo({
24
+ top: startValues.scrollTop
25
+ + (top - startValues.scrollTop) * data.easing,
26
+ left: startValues.scrollLeft
27
+ + (left - startValues.scrollLeft) * data.easing,
28
+ behavior: 'auto',
29
+ });
30
+ }
31
+ });
32
+ timeline.addCallback('end', function () {
33
+ resolve();
34
+ });
35
+ timeline.play();
36
+ return;
37
+ }
38
+ reject();
39
+ });
40
+ }
41
+ exports.default = scrollTo;
@@ -0,0 +1,181 @@
1
+ import { selectOne } from 'vevet-dom';
2
+ import onScroll from '../../../utils/listeners/onScroll';
3
+ import { Component } from '../../../base/Component';
4
+ import clampScope from '../../../utils/math/clampScope';
5
+ import getScrollValues from '../../../utils/scroll/getScrollValues';
6
+ /**
7
+ * Elements into viewport
8
+ */
9
+ export class ScrollSectionProgress extends Component {
10
+ constructor(initialProp, init = true) {
11
+ super(initialProp, false);
12
+ // get scroll container
13
+ if (typeof this.prop.container === 'string') {
14
+ this._scrollContainer = selectOne(this.prop.container);
15
+ }
16
+ else {
17
+ this._scrollContainer = this.prop.container;
18
+ }
19
+ // get section element
20
+ if (typeof this.prop.section === 'string') {
21
+ this._section = selectOne(this.prop.section);
22
+ }
23
+ else {
24
+ this._section = this.prop.section;
25
+ }
26
+ // set defaults
27
+ this._progress = -0.001;
28
+ this._scopeScroll = [0, 0];
29
+ this._scopeIn = [0, 0];
30
+ this._scopeMove = [0, 0];
31
+ this._scopeOut = [0, 0];
32
+ // initialize the class
33
+ if (init) {
34
+ this.init();
35
+ }
36
+ }
37
+ _getDefaultProp() {
38
+ return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, viewportTarget: '', resizeTimeout: 0 });
39
+ }
40
+ get scrollContainer() {
41
+ return this._scrollContainer;
42
+ }
43
+ get section() {
44
+ return this._section;
45
+ }
46
+ get scopeScroll() {
47
+ return this._scopeScroll;
48
+ }
49
+ get scopeIn() {
50
+ return this._scopeIn;
51
+ }
52
+ get scopeMove() {
53
+ return this._scopeMove;
54
+ }
55
+ get scopeOut() {
56
+ return this._scopeOut;
57
+ }
58
+ /**
59
+ * Global progress
60
+ */
61
+ get progress() {
62
+ return this._progress;
63
+ }
64
+ set progress(val) {
65
+ this._progress = val;
66
+ }
67
+ init() {
68
+ super.init();
69
+ }
70
+ // Set Module Events
71
+ _setEvents() {
72
+ super._setEvents();
73
+ // set resize events
74
+ this.addViewportCallback(this.prop.viewportTarget, () => {
75
+ this.resize();
76
+ }, {
77
+ timeout: this.prop.resizeTimeout,
78
+ });
79
+ // resize on page loaded
80
+ this._loadedEvent = this._app.onPageLoaded();
81
+ this._loadedEvent.then(() => {
82
+ this.resize();
83
+ }).catch(() => { });
84
+ // set scroll events
85
+ this._scrollEvent = onScroll({
86
+ container: this.prop.container,
87
+ callback: this._handleScroll.bind(this),
88
+ });
89
+ }
90
+ _onPropMutate() {
91
+ super._onPropMutate();
92
+ this.resize();
93
+ }
94
+ /**
95
+ * 'in' progress
96
+ */
97
+ get progressIn() {
98
+ return clampScope(this.progress, this.scopeIn) || 0;
99
+ }
100
+ /**
101
+ * 'out' progress
102
+ */
103
+ get progressOut() {
104
+ return clampScope(this.progress, this.scopeOut) || 0;
105
+ }
106
+ /**
107
+ * 'move' progress
108
+ */
109
+ get progressMove() {
110
+ return clampScope(this.progress, this.scopeMove) || 0;
111
+ }
112
+ /**
113
+ * Handle scroll event
114
+ */
115
+ _handleScroll() {
116
+ // calculate scopes
117
+ const scrollData = getScrollValues(this.scrollContainer);
118
+ if (!scrollData) {
119
+ return;
120
+ }
121
+ this._render(scrollData);
122
+ }
123
+ /**
124
+ * Resize the scene
125
+ */
126
+ resize() {
127
+ // calculate scopes
128
+ const scrollData = getScrollValues(this.scrollContainer);
129
+ if (!scrollData) {
130
+ return;
131
+ }
132
+ // get sizes
133
+ const bounding = this.section.getBoundingClientRect();
134
+ const vHeight = this._app.viewport.height;
135
+ // calculate scroll scope
136
+ const inStart = scrollData.scrollTop + bounding.top - vHeight;
137
+ const moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
138
+ const scrollLine = moveEnd - inStart;
139
+ this._scopeScroll = [inStart, moveEnd];
140
+ // calculate scopes
141
+ this._scopeIn = [0, vHeight / scrollLine];
142
+ this._scopeOut = [1 - vHeight / scrollLine, 1];
143
+ this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
144
+ // launch callbacks
145
+ this.callbacks.tbt('resize', false);
146
+ // render the scene
147
+ this._render(scrollData, true);
148
+ }
149
+ /**
150
+ * Render the scene
151
+ */
152
+ _render(scrollData, force = false) {
153
+ const canRender = this._canRender(scrollData, force);
154
+ if (!canRender) {
155
+ return;
156
+ }
157
+ this.callbacks.tbt('render', false);
158
+ }
159
+ /**
160
+ * Check if the section can be rendered
161
+ */
162
+ _canRender(scrollData, force = false) {
163
+ if (!scrollData) {
164
+ return false;
165
+ }
166
+ const { scrollTop } = scrollData;
167
+ const prevProgress = this.progress;
168
+ const progress = clampScope(scrollTop, [this._scopeScroll[0], this._scopeScroll[1]]) || 0;
169
+ this.progress = progress;
170
+ return force || (progress !== prevProgress);
171
+ }
172
+ /**
173
+ * Destroy the module
174
+ */
175
+ _destroy() {
176
+ var _a, _b;
177
+ super._destroy();
178
+ (_a = this._scrollEvent) === null || _a === void 0 ? void 0 : _a.remove();
179
+ (_b = this._loadedEvent) === null || _b === void 0 ? void 0 : _b.cancel();
180
+ }
181
+ }
package/build/es/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as common from './utils/common';
2
2
  import * as listeners from './utils/listeners';
3
3
  import * as math from './utils/math';
4
+ import * as scroll from './utils/scroll';
4
5
  import * as GeneralTypes from './utils/types/general';
5
6
  import { Application } from './app/Application';
6
7
  import { Viewport } from './app/events/Viewport';
@@ -28,11 +29,13 @@ import { ScrollEventsBase } from './components/scroll/scrollable/ScrollEventsBas
28
29
  import { ScrollView } from './components/scroll/scrollable/ScrollView';
29
30
  import { SmoothScrollKeyboardPlugin } from './components/scroll/plugins/SmoothScrollKeyboardPlugin';
30
31
  import { SmoothScrollDragPlugin } from './components/scroll/plugins/SmoothScrollDragPlugin';
32
+ import { ScrollSectionProgress } from './components/scroll/section/ScrollSectionProgress';
31
33
  import { SplitText } from './components/text/SplitText';
32
34
  import { CustomCursor } from './components/cursor/CustomCursor';
33
35
  const utils = {
34
36
  common,
35
37
  listeners,
36
38
  math,
39
+ scroll,
37
40
  };
38
- export { utils, GeneralTypes, Application, Viewport, PageLoad, Callbacks, MutableProp, Module, Component, Plugin, Page, WheelHandler, AnimationFrame, StaticTimeline, Timeline, Preloader, ProgressPreloader, Dragger, DraggerMove, DraggerDirection, Ctx2D, Ctx2DPrerender, SmoothScroll, ScrollBar, ScrollEventsBase, ScrollView, SmoothScrollKeyboardPlugin, SmoothScrollDragPlugin, SplitText, CustomCursor, };
41
+ export { utils, GeneralTypes, Application, Viewport, PageLoad, Callbacks, MutableProp, Module, Component, Plugin, Page, WheelHandler, AnimationFrame, StaticTimeline, Timeline, Preloader, ProgressPreloader, Dragger, DraggerMove, DraggerDirection, Ctx2D, Ctx2DPrerender, SmoothScroll, ScrollBar, ScrollEventsBase, ScrollView, SmoothScrollKeyboardPlugin, SmoothScrollDragPlugin, ScrollSectionProgress, SplitText, CustomCursor, };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Get scroll values of a certain element
3
+ */
4
+ export default function getScrollValues(selector = window) {
5
+ if (selector) {
6
+ const scrollTop = selector instanceof Window
7
+ ? selector.pageYOffset : selector.scrollTop;
8
+ const scrollLeft = selector instanceof Window
9
+ ? selector.pageXOffset : selector.scrollLeft;
10
+ return {
11
+ scrollTop,
12
+ scrollLeft,
13
+ };
14
+ }
15
+ return undefined;
16
+ }
@@ -0,0 +1,4 @@
1
+ import getValues from './getScrollValues';
2
+ import scrollTo from './scrollTo';
3
+ import scrollToElement from './scrollToElement';
4
+ export { getValues, scrollTo as to, scrollToElement as toElement, };