vevet 2.0.1-dev.9 → 2.0.2

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 (130) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/app/Application.js +8 -8
  3. package/build/cjs/app/events/PageLoad.js +3 -3
  4. package/build/cjs/app/events/Viewport.js +5 -5
  5. package/build/cjs/base/Callbacks.js +3 -3
  6. package/build/cjs/base/Module.js +16 -7
  7. package/build/cjs/base/MutableProp.js +10 -10
  8. package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
  9. package/build/cjs/components/canvas/Ctx2D.js +7 -3
  10. package/build/cjs/components/canvas/Ctx2DPrerender.js +17 -3
  11. package/build/cjs/components/cursor/CustomCursor.js +12 -12
  12. package/build/cjs/components/dragger/Dragger.js +8 -8
  13. package/build/cjs/components/dragger/DraggerMove.js +2 -2
  14. package/build/cjs/components/loading/Preloader.js +5 -5
  15. package/build/cjs/components/loading/ProgressPreloader.js +17 -5
  16. package/build/cjs/components/page/Page.js +37 -9
  17. package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +2 -2
  18. package/build/cjs/components/scroll/scrollable/ScrollEventsBase.js +1 -1
  19. package/build/cjs/components/scroll/scrollable/ScrollView.js +133 -73
  20. package/build/cjs/components/scroll/scrollbar/Bar.js +18 -15
  21. package/build/cjs/components/scroll/scrollbar/ScrollBar.js +9 -7
  22. package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +26 -22
  23. package/build/cjs/components/text/SplitText.js +34 -12
  24. package/build/cjs/components/timeline/StaticTimeline.js +4 -4
  25. package/build/cjs/components/timeline/Timeline.js +2 -2
  26. package/build/cjs/handlers/wheel/WheelHandler.js +4 -4
  27. package/build/cjs/utils/common/mergeWithoutArrays.js +1 -1
  28. package/build/cjs/utils/common/randID.js +2 -2
  29. package/build/cjs/utils/listeners/onScroll.js +66 -28
  30. package/build/cjs/utils/math/{boundVal.js → clamp.js} +3 -3
  31. package/build/cjs/utils/math/clampScope.js +16 -0
  32. package/build/cjs/utils/math/inScope.js +10 -0
  33. package/build/cjs/utils/math/index.js +13 -7
  34. package/build/cjs/utils/math/scoped.js +18 -0
  35. package/build/cjs/utils/math/{spreadScopeProgress.js → spreadScope.js} +2 -2
  36. package/build/cjs/utils/math/wrap.js +13 -0
  37. package/build/es/base/Module.js +2 -4
  38. package/build/es/components/animation-frame/AnimationFrame.js +2 -2
  39. package/build/es/components/canvas/Ctx2D.js +6 -2
  40. package/build/es/components/canvas/Ctx2DPrerender.js +16 -2
  41. package/build/es/components/loading/ProgressPreloader.js +14 -2
  42. package/build/es/components/page/Page.js +32 -8
  43. package/build/es/components/scroll/scrollable/ScrollView.js +112 -62
  44. package/build/es/components/scroll/scrollbar/Bar.js +9 -6
  45. package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
  46. package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +13 -9
  47. package/build/es/components/text/SplitText.js +25 -3
  48. package/build/es/components/timeline/StaticTimeline.js +3 -3
  49. package/build/es/components/timeline/Timeline.js +2 -2
  50. package/build/es/utils/listeners/onScroll.js +65 -28
  51. package/build/es/utils/math/{boundVal.js → clamp.js} +2 -2
  52. package/build/es/utils/math/clampScope.js +8 -0
  53. package/build/es/utils/math/inScope.js +6 -0
  54. package/build/es/utils/math/index.js +7 -4
  55. package/build/es/utils/math/scoped.js +14 -0
  56. package/build/es/utils/math/{spreadScopeProgress.js → spreadScope.js} +1 -1
  57. package/build/es/utils/math/wrap.js +10 -0
  58. package/build/types/base/Module.d.ts.map +1 -1
  59. package/build/types/components/canvas/Ctx2D.d.ts +9 -0
  60. package/build/types/components/canvas/Ctx2D.d.ts.map +1 -1
  61. package/build/types/components/canvas/Ctx2DPrerender.d.ts +1 -1
  62. package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -1
  63. package/build/types/components/loading/ProgressPreloader.d.ts +7 -0
  64. package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
  65. package/build/types/components/page/Page.d.ts +2 -0
  66. package/build/types/components/page/Page.d.ts.map +1 -1
  67. package/build/types/components/scroll/scrollable/ScrollView.d.ts +40 -14
  68. package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
  69. package/build/types/components/scroll/scrollbar/Bar.d.ts.map +1 -1
  70. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts +4 -0
  71. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts.map +1 -1
  72. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts +4 -0
  73. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts.map +1 -1
  74. package/build/types/components/text/SplitText.d.ts +10 -0
  75. package/build/types/components/text/SplitText.d.ts.map +1 -1
  76. package/build/types/utils/listeners/onScroll.d.ts +10 -6
  77. package/build/types/utils/listeners/onScroll.d.ts.map +1 -1
  78. package/build/types/utils/math/clamp.d.ts +5 -0
  79. package/build/types/utils/math/clamp.d.ts.map +1 -0
  80. package/build/types/utils/math/clampScope.d.ts +5 -0
  81. package/build/types/utils/math/clampScope.d.ts.map +1 -0
  82. package/build/types/utils/math/inScope.d.ts +5 -0
  83. package/build/types/utils/math/inScope.d.ts.map +1 -0
  84. package/build/types/utils/math/index.d.ts +7 -4
  85. package/build/types/utils/math/index.d.ts.map +1 -1
  86. package/build/types/utils/math/scoped.d.ts +12 -0
  87. package/build/types/utils/math/scoped.d.ts.map +1 -0
  88. package/build/types/utils/math/spreadScope.d.ts +5 -0
  89. package/build/types/utils/math/spreadScope.d.ts.map +1 -0
  90. package/build/types/utils/math/wrap.d.ts +5 -0
  91. package/build/types/utils/math/wrap.d.ts.map +1 -0
  92. package/package.json +3 -3
  93. package/src/ts/base/Module.ts +5 -4
  94. package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
  95. package/src/ts/components/canvas/Ctx2D.ts +16 -1
  96. package/src/ts/components/canvas/Ctx2DPrerender.ts +19 -6
  97. package/src/ts/components/loading/ProgressPreloader.ts +21 -2
  98. package/src/ts/components/page/Page.ts +34 -8
  99. package/src/ts/components/scroll/scrollable/ScrollView.ts +155 -86
  100. package/src/ts/components/scroll/scrollbar/Bar.ts +9 -6
  101. package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
  102. package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +17 -8
  103. package/src/ts/components/text/SplitText.ts +38 -2
  104. package/src/ts/components/timeline/StaticTimeline.ts +4 -4
  105. package/src/ts/components/timeline/Timeline.ts +2 -2
  106. package/src/ts/utils/listeners/onScroll.ts +101 -38
  107. package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
  108. package/src/ts/utils/math/clampScope.ts +16 -0
  109. package/src/ts/utils/math/inScope.ts +9 -0
  110. package/src/ts/utils/math/index.ts +12 -6
  111. package/src/ts/utils/math/scoped.ts +17 -0
  112. package/src/ts/utils/math/{spreadScopeProgress.ts → spreadScope.ts} +2 -2
  113. package/src/ts/utils/math/wrap.ts +18 -0
  114. package/build/cjs/components/scroll/custom-scroll/CustomScroll.js +0 -517
  115. package/build/cjs/components/split-text/SplitText.js +0 -233
  116. package/build/cjs/utils/math/scopeProgress.js +0 -25
  117. package/build/es/components/scroll/custom-scroll/CustomScroll.js +0 -486
  118. package/build/es/components/split-text/SplitText.js +0 -199
  119. package/build/es/utils/math/scopeProgress.js +0 -22
  120. package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts +0 -322
  121. package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts.map +0 -1
  122. package/build/types/components/split-text/SplitText.d.ts +0 -118
  123. package/build/types/components/split-text/SplitText.d.ts.map +0 -1
  124. package/build/types/utils/math/boundVal.d.ts +0 -5
  125. package/build/types/utils/math/boundVal.d.ts.map +0 -1
  126. package/build/types/utils/math/scopeProgress.d.ts +0 -20
  127. package/build/types/utils/math/scopeProgress.d.ts.map +0 -1
  128. package/build/types/utils/math/spreadScopeProgress.d.ts +0 -5
  129. package/build/types/utils/math/spreadScopeProgress.d.ts.map +0 -1
  130. package/src/ts/utils/math/scopeProgress.ts +0 -23
@@ -45,6 +45,7 @@ var Page = /** @class */ (function (_super) {
45
45
  if (init === void 0) { init = true; }
46
46
  var _this = _super.call(this, initialProp, false) || this;
47
47
  // set default vars
48
+ _this._blocked = false;
48
49
  _this._created = false;
49
50
  _this._shown = false;
50
51
  _this._hidden = false;
@@ -56,6 +57,13 @@ var Page = /** @class */ (function (_super) {
56
57
  }
57
58
  return _this;
58
59
  }
60
+ Object.defineProperty(Page.prototype, "blocked", {
61
+ get: function () {
62
+ return this._blocked;
63
+ },
64
+ enumerable: false,
65
+ configurable: true
66
+ });
59
67
  Object.defineProperty(Page.prototype, "created", {
60
68
  get: function () {
61
69
  return this._created;
@@ -86,7 +94,7 @@ var Page = /** @class */ (function (_super) {
86
94
  });
87
95
  Object.defineProperty(Page.prototype, "pageClassName", {
88
96
  get: function () {
89
- return this._app.prefix + "page-" + this.prop.name;
97
+ return "".concat(this._app.prefix, "page-").concat(this.prop.name);
90
98
  },
91
99
  enumerable: false,
92
100
  configurable: true
@@ -103,11 +111,12 @@ var Page = /** @class */ (function (_super) {
103
111
  if (viaAJAX === void 0) { viaAJAX = false; }
104
112
  return new Promise(function (resolve, reject) {
105
113
  _this.canCreate().then(function () {
106
- if (_this.created) {
114
+ if (_this.created || _this.blocked) {
115
+ reject();
107
116
  return;
108
117
  }
109
118
  // update vars
110
- _this._created = true;
119
+ _this._blocked = true;
111
120
  _this._shown = false;
112
121
  _this._hidden = false;
113
122
  _this._destroyed = false;
@@ -119,7 +128,11 @@ var Page = /** @class */ (function (_super) {
119
128
  // actions
120
129
  _this._create().then(function () {
121
130
  _this.callbacks.tbt('create', false);
131
+ _this._blocked = false;
132
+ _this._created = true;
122
133
  resolve();
134
+ }).catch(function () {
135
+ reject();
123
136
  });
124
137
  }).catch(function () {
125
138
  reject();
@@ -154,18 +167,23 @@ var Page = /** @class */ (function (_super) {
154
167
  var _this = this;
155
168
  return new Promise(function (resolve, reject) {
156
169
  _this.canShow().then(function () {
157
- if (_this.shown) {
170
+ if (_this.shown || _this.blocked) {
171
+ reject();
158
172
  return;
159
173
  }
160
174
  // update vars
175
+ _this._blocked = true;
161
176
  _this._created = true;
162
- _this._shown = true;
163
177
  _this._hidden = false;
164
178
  _this._destroyed = false;
165
179
  // actions
166
180
  _this._show().then(function () {
167
181
  _this.callbacks.tbt('show', false);
182
+ _this._blocked = false;
183
+ _this._shown = true;
168
184
  resolve();
185
+ }).catch(function () {
186
+ reject();
169
187
  });
170
188
  // launch events
171
189
  }).catch(function () {
@@ -201,18 +219,23 @@ var Page = /** @class */ (function (_super) {
201
219
  var _this = this;
202
220
  return new Promise(function (resolve, reject) {
203
221
  _this.canHide().then(function () {
204
- if (_this.hidden) {
222
+ if (_this.hidden || _this.blocked) {
223
+ reject();
205
224
  return;
206
225
  }
207
226
  // update vars
227
+ _this._blocked = true;
208
228
  _this._created = true;
209
229
  _this._shown = false;
210
- _this._hidden = true;
211
230
  _this._destroyed = false;
212
231
  // actions
213
232
  _this._hide().then(function () {
214
233
  _this.callbacks.tbt('hide', false);
234
+ _this._blocked = false;
235
+ _this._hidden = true;
215
236
  resolve();
237
+ }).catch(function () {
238
+ reject();
216
239
  });
217
240
  }).catch(function () {
218
241
  reject();
@@ -247,21 +270,26 @@ var Page = /** @class */ (function (_super) {
247
270
  var _this = this;
248
271
  return new Promise(function (resolve, reject) {
249
272
  _this.canDestroy().then(function () {
250
- if (_this.destroyed) {
273
+ if (_this.destroyed || _this.blocked) {
274
+ reject();
251
275
  return;
252
276
  }
253
277
  // change vars
278
+ _this._blocked = true;
254
279
  _this._created = false;
255
280
  _this._shown = false;
256
281
  _this._hidden = true;
257
- _this._destroyed = true;
258
282
  // update page
259
283
  _this._app.page = false;
260
284
  // remove page class
261
285
  _this._app.html.classList.remove(_this.pageClassName);
262
286
  // actions
263
287
  _this._destroy().then(function () {
288
+ _this._blocked = false;
289
+ _this._destroyed = true;
264
290
  resolve();
291
+ }).catch(function () {
292
+ reject();
265
293
  });
266
294
  }).catch(function () {
267
295
  reject();
@@ -119,12 +119,12 @@ var SmoothScrollKeyboardPlugin = /** @class */ (function (_super) {
119
119
  SmoothScrollKeyboardPlugin.prototype._handleTab = function () {
120
120
  var _this = this;
121
121
  // get active element and scroll to it
122
- timeoutCallback_1.default(function () {
122
+ (0, timeoutCallback_1.default)(function () {
123
123
  var scroll = _this._component;
124
124
  var activeElement = document.activeElement;
125
125
  // skip elements that do not belong to the SmoothScroll outer
126
126
  if (!(activeElement instanceof HTMLElement)
127
- || !vevet_dom_1.childOf(activeElement, scroll.outer)) {
127
+ || !(0, vevet_dom_1.childOf)(activeElement, scroll.outer)) {
128
128
  return;
129
129
  }
130
130
  // get boundings
@@ -39,7 +39,7 @@ var ScrollEventsBase = /** @class */ (function (_super) {
39
39
  var _this = _super.call(this, initialProp, false) || this;
40
40
  // get scroll container
41
41
  if (typeof _this.prop.container === 'string') {
42
- _this._scrollContainer = vevet_dom_1.selectOne(_this.prop.container);
42
+ _this._scrollContainer = (0, vevet_dom_1.selectOne)(_this.prop.container);
43
43
  }
44
44
  else {
45
45
  _this._scrollContainer = _this.prop.container;
@@ -25,16 +25,24 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
28
37
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
39
  };
31
40
  Object.defineProperty(exports, "__esModule", { value: true });
32
41
  exports.ScrollView = void 0;
33
- var vevet_dom_1 = require("vevet-dom");
34
42
  var ScrollEventsBase_1 = require("./ScrollEventsBase");
35
43
  var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
36
44
  var listeners_1 = require("../../../utils/listeners");
37
- var boundVal_1 = __importDefault(require("../../../utils/math/boundVal"));
45
+ var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
38
46
  var timeoutCallback_1 = __importDefault(require("../../../utils/common/timeoutCallback"));
39
47
  /**
40
48
  * Elements into viewport
@@ -45,10 +53,10 @@ var ScrollView = /** @class */ (function (_super) {
45
53
  if (init === void 0) { init = true; }
46
54
  var _this = _super.call(this, initialProp, false) || this;
47
55
  _this._scrollEvent = undefined;
48
- _this._intersectionObserver = undefined;
56
+ _this._intersectionObserverIn = undefined;
57
+ _this._intersectionObserverOut = undefined;
49
58
  _this._firstStart = true;
50
- // get view elements
51
- _this.updateElements();
59
+ _this._elements = __spreadArray([], _this.prop.elements, true);
52
60
  // initialize the class
53
61
  if (init) {
54
62
  _this.init();
@@ -57,17 +65,26 @@ var ScrollView = /** @class */ (function (_super) {
57
65
  }
58
66
  Object.defineProperty(ScrollView.prototype, "prefix", {
59
67
  get: function () {
60
- return this._app.prefix + "scroll-view";
68
+ return "".concat(this._app.prefix, "scroll-view");
61
69
  },
62
70
  enumerable: false,
63
71
  configurable: true
64
72
  });
65
73
  ScrollView.prototype._getDefaultProp = function () {
66
- return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, elements: "." + this.prefix + "__el", threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
74
+ return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { enabled: true, container: window, elements: [], threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true, resizeTimeout: 0 });
67
75
  };
76
+ Object.defineProperty(ScrollView.prototype, "elements", {
77
+ /**
78
+ * Elements to seek
79
+ */
80
+ get: function () {
81
+ return this._elements;
82
+ },
83
+ enumerable: false,
84
+ configurable: true
85
+ });
68
86
  ScrollView.prototype.init = function () {
69
87
  _super.prototype.init.call(this);
70
- this.seekBounding();
71
88
  };
72
89
  // Set Module Events
73
90
  ScrollView.prototype._setEvents = function () {
@@ -76,20 +93,23 @@ var ScrollView = /** @class */ (function (_super) {
76
93
  this.resize();
77
94
  this.addViewportCallback('', function () {
78
95
  _this.resize();
96
+ }, {
97
+ timeout: this.prop.resizeTimeout,
79
98
  });
80
99
  };
81
100
  ScrollView.prototype._onPropMutate = function () {
82
101
  _super.prototype._onPropMutate.call(this);
83
- this._removeViewEvents();
84
- this.updateElements();
85
- this._setViewEvents();
102
+ this.resize();
86
103
  };
87
104
  /**
88
105
  * Resize the scene
89
106
  */
90
107
  ScrollView.prototype.resize = function () {
91
108
  this._removeViewEvents();
92
- this._setViewEvents();
109
+ if (this.prop.enabled) {
110
+ this._setViewEvents();
111
+ this.seekBounding();
112
+ }
93
113
  };
94
114
  /**
95
115
  * Set View events: scroll or intersection
@@ -97,85 +117,63 @@ var ScrollView = /** @class */ (function (_super) {
97
117
  ScrollView.prototype._setViewEvents = function () {
98
118
  var _this = this;
99
119
  // set intersection observer
100
- if (listeners_1.intersectionObserverSupported() && this.prop.useIntersectionObserver) {
120
+ if ((0, listeners_1.intersectionObserverSupported)() && this.prop.useIntersectionObserver) {
101
121
  // get intersecton margins
102
122
  var scrollContainerBounding = this.scrollContainerBounding;
103
123
  var xMargin = this._firstStart
104
124
  ? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
105
125
  var yMargin = this._firstStart
106
126
  ? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
107
- // create intersection observer
108
- this._intersectionObserver = new IntersectionObserver(this._handleIntersectionObserver.bind(this), {
127
+ // create intersection observers
128
+ this._intersectionObserverIn = new IntersectionObserver(this._handleIntersectionObserverIn.bind(this), {
109
129
  root: this.intersectionRoot,
110
130
  threshold: 0,
111
- rootMargin: "0px " + xMargin + "px " + yMargin + "px 0px",
131
+ rootMargin: "0px ".concat(xMargin, "px ").concat(yMargin, "px 0px"),
112
132
  });
113
- // add elements
114
- if (this.elements) {
133
+ this.elements.forEach(function (el) {
134
+ var _a;
135
+ (_a = _this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(el);
136
+ });
137
+ if (this.prop.states === 'inout') {
138
+ this._intersectionObserverOut = new IntersectionObserver(this._handleIntersectionObserverOut.bind(this), {
139
+ root: this.intersectionRoot,
140
+ threshold: 0,
141
+ rootMargin: '0px 0px 0px 0px',
142
+ });
115
143
  this.elements.forEach(function (el) {
116
144
  var _a;
117
- (_a = _this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
145
+ (_a = _this._intersectionObserverOut) === null || _a === void 0 ? void 0 : _a.observe(el);
118
146
  });
119
147
  }
120
148
  }
121
149
  else {
122
150
  // set scroll bounding events
123
- this._scrollEvent = onScroll_1.default(this.prop.container, this._handleScroll.bind(this));
151
+ this._scrollEvent = (0, onScroll_1.default)({
152
+ container: this.prop.container,
153
+ callback: this._handleScroll.bind(this),
154
+ });
124
155
  }
125
156
  };
126
157
  /**
127
158
  * Remove View events: scroll or intersection
128
159
  */
129
160
  ScrollView.prototype._removeViewEvents = function () {
161
+ var _a, _b;
130
162
  // remove scroll events
131
163
  if (this._scrollEvent) {
132
164
  this._scrollEvent.remove();
133
165
  this._scrollEvent = undefined;
134
166
  }
135
- // destroy intersection observer
136
- if (this._intersectionObserver) {
137
- this._intersectionObserver.disconnect();
138
- this._intersectionObserver = undefined;
139
- }
140
- };
141
- Object.defineProperty(ScrollView.prototype, "elements", {
142
- /**
143
- * Element to seek
144
- */
145
- get: function () {
146
- return this._elements;
147
- },
148
- enumerable: false,
149
- configurable: true
150
- });
151
- /**
152
- * Update elements
153
- */
154
- ScrollView.prototype.updateElements = function () {
155
- var _this = this;
156
- // check if elements exist
157
- if (typeof this.elements === 'undefined') {
158
- this._elements = [];
159
- }
160
- // unobserve old elements
161
- this.elements.forEach(function (el) {
162
- if (_this._intersectionObserver) {
163
- _this._intersectionObserver.unobserve(el);
164
- }
165
- });
166
- // update elements
167
- this._elements = Array.from(vevet_dom_1.selectAll(this.prop.elements, this.domParent || undefined)).filter(function (el) { return !el.classList.contains(_this.prop.classToToggle); });
168
- // add them to the observer
169
- this._elements.forEach(function (el) {
170
- if (_this._intersectionObserver) {
171
- _this._intersectionObserver.observe(el);
172
- }
173
- });
167
+ // destroy intersection observers
168
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.disconnect();
169
+ this._intersectionObserverIn = undefined;
170
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.disconnect();
171
+ this._intersectionObserverOut = undefined;
174
172
  };
175
173
  /**
176
174
  * Event on IntersectionObserver
177
175
  */
178
- ScrollView.prototype._handleIntersectionObserver = function (data) {
176
+ ScrollView.prototype._handleIntersectionObserverIn = function (data) {
179
177
  var parentBounding = this._firstStart ? this.scrollContainerBounding : false;
180
178
  for (var index = 0; index < data.length; index += 1) {
181
179
  var entry = data[index];
@@ -183,7 +181,9 @@ var ScrollView = /** @class */ (function (_super) {
183
181
  if (this._firstStart && !!parentBounding && entry.isIntersecting) {
184
182
  delay = this._elementInViewportData(entry.target, parentBounding).delay;
185
183
  }
186
- this._handleInOut(entry.target, entry.isIntersecting, delay);
184
+ if (entry.isIntersecting) {
185
+ this._handleInOut(entry.target, entry.isIntersecting, delay);
186
+ }
187
187
  }
188
188
  this._processUnusedElements();
189
189
  // change states
@@ -192,6 +192,17 @@ var ScrollView = /** @class */ (function (_super) {
192
192
  this.resize();
193
193
  }
194
194
  };
195
+ /**
196
+ * Event on IntersectionObserver
197
+ */
198
+ ScrollView.prototype._handleIntersectionObserverOut = function (data) {
199
+ for (var index = 0; index < data.length; index += 1) {
200
+ var entry = data[index];
201
+ if (!entry.isIntersecting) {
202
+ this._handleInOut(entry.target, entry.isIntersecting, 0);
203
+ }
204
+ }
205
+ };
195
206
  /**
196
207
  * Event on Scroll
197
208
  */
@@ -204,7 +215,7 @@ var ScrollView = /** @class */ (function (_super) {
204
215
  */
205
216
  ScrollView.prototype.seekBounding = function () {
206
217
  // check if calculations are done through getBoundingClientRect
207
- if (listeners_1.intersectionObserverSupported() && this.prop.useIntersectionObserver) {
218
+ if ((0, listeners_1.intersectionObserverSupported)() && this.prop.useIntersectionObserver) {
208
219
  return;
209
220
  }
210
221
  // vars
@@ -214,7 +225,9 @@ var ScrollView = /** @class */ (function (_super) {
214
225
  var el = this.elements[index];
215
226
  var elData = this._elementInViewportData(el, scrollContainerBounding);
216
227
  var delay = elData.isIntersecting ? elData.delay : 0;
217
- this._handleInOut(el, elData.isIntersecting, delay);
228
+ if (typeof elData.isIntersecting === 'boolean') {
229
+ this._handleInOut(el, elData.isIntersecting, delay);
230
+ }
218
231
  }
219
232
  this._processUnusedElements();
220
233
  // change states
@@ -230,7 +243,7 @@ var ScrollView = /** @class */ (function (_super) {
230
243
  var threshold = this._firstStart ? 1 : propThreshold;
231
244
  var bounding = el.getBoundingClientRect();
232
245
  // check if the element is intersecting
233
- var isIntersecting = false;
246
+ var isIntersecting;
234
247
  if (bounding.top < parentBounding.top + parentBounding.height * threshold
235
248
  && bounding.left < parentBounding.left + parentBounding.width * threshold) {
236
249
  if (states === 'in') {
@@ -244,11 +257,15 @@ var ScrollView = /** @class */ (function (_super) {
244
257
  isIntersecting = true;
245
258
  }
246
259
  }
260
+ else if (bounding.top > parentBounding.top + parentBounding.height
261
+ || bounding.left > parentBounding.left + parentBounding.width) {
262
+ isIntersecting = false;
263
+ }
247
264
  // calculate delay only if it is enabled & calculations
248
265
  // are done for the first time
249
266
  var delay = 0;
250
267
  if (!!useDelay && this._firstStart) {
251
- var progress = boundVal_1.default(useDelay.dir === 'x'
268
+ var progress = (0, clamp_1.default)(useDelay.dir === 'x'
252
269
  ? (bounding.left - parentBounding.left) / parentBounding.width
253
270
  : (bounding.top - parentBounding.top) / parentBounding.height, [0, 1]);
254
271
  delay = progress * useDelay.max;
@@ -273,17 +290,19 @@ var ScrollView = /** @class */ (function (_super) {
273
290
  // update props
274
291
  el.scrollViewIn = inViewport;
275
292
  // toggle classes
276
- timeoutCallback_1.default(function () {
277
- el.classList.toggle(_this.prop.classToToggle, inViewport);
278
- }, delay);
293
+ if (this.prop.classToToggle) {
294
+ (0, timeoutCallback_1.default)(function () {
295
+ el.classList.toggle(_this.prop.classToToggle, inViewport);
296
+ }, delay);
297
+ }
279
298
  // process callbacks
280
299
  if (inViewport && (states === 'in' || states === 'inout')) {
281
- timeoutCallback_1.default(function () {
300
+ (0, timeoutCallback_1.default)(function () {
282
301
  _this.callbacks.tbt('in', el);
283
302
  }, delay);
284
303
  }
285
304
  else if (!inViewport && states === 'inout') {
286
- timeoutCallback_1.default(function () {
305
+ (0, timeoutCallback_1.default)(function () {
287
306
  _this.callbacks.tbt('out', el);
288
307
  }, delay);
289
308
  }
@@ -299,12 +318,53 @@ var ScrollView = /** @class */ (function (_super) {
299
318
  // remove unused elements
300
319
  var elementsToRemove = this._elements.filter(function (el) { return el.scrollViewIn; });
301
320
  elementsToRemove.forEach(function (el) {
302
- if (_this._intersectionObserver) {
303
- _this._intersectionObserver.unobserve(el);
304
- }
321
+ var _a, _b;
322
+ (_a = _this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(el);
323
+ (_b = _this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(el);
305
324
  });
306
325
  this._elements = this._elements.filter(function (el) { return !el.scrollViewIn; });
307
326
  };
327
+ /**
328
+ * Add a view element
329
+ */
330
+ ScrollView.prototype.addElement = function (element) {
331
+ var _this = this;
332
+ var _a, _b;
333
+ var viewEl = element;
334
+ viewEl.scrollViewIn = undefined;
335
+ this._elements.push(element);
336
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(element);
337
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.observe(element);
338
+ if (this.prop.enabled) {
339
+ this.seekBounding();
340
+ }
341
+ return {
342
+ remove: function () {
343
+ _this.removeElement(element);
344
+ },
345
+ };
346
+ };
347
+ /**
348
+ * Remove a view element
349
+ */
350
+ ScrollView.prototype.removeElement = function (element) {
351
+ var _a, _b;
352
+ var viewEl = element;
353
+ viewEl.scrollViewIn = undefined;
354
+ this._elements = this._elements.filter(function (el) { return el !== element; });
355
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(element);
356
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(element);
357
+ };
358
+ /**
359
+ * Remove all view elements
360
+ */
361
+ ScrollView.prototype.removeElements = function () {
362
+ var _this = this;
363
+ this._elements.forEach(function (el) {
364
+ _this.removeElement(el);
365
+ });
366
+ this._elements = [];
367
+ };
308
368
  /**
309
369
  * Destroy the module
310
370
  */
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var vevet_dom_1 = require("vevet-dom");
7
7
  var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
8
- var boundVal_1 = __importDefault(require("../../../utils/math/boundVal"));
8
+ var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
9
9
  var DraggerMove_1 = require("../../dragger/DraggerMove");
10
10
  var SmoothScroll_1 = require("../smooth-scroll/SmoothScroll");
11
11
  var Bar = /** @class */ (function () {
@@ -26,18 +26,18 @@ var Bar = /** @class */ (function () {
26
26
  this._actionTimeout = undefined;
27
27
  this._dragger = undefined;
28
28
  // create outer
29
- var outerClassNames = prefix + " " + prefix + "_" + dir;
29
+ var outerClassNames = "".concat(prefix, " ").concat(prefix, "_").concat(dir);
30
30
  if (container instanceof Window) {
31
31
  outerClassNames += ' in-window';
32
32
  }
33
- this._outer = vevet_dom_1.createElement('div', {
33
+ this._outer = (0, vevet_dom_1.createElement)('div', {
34
34
  parent: domParent,
35
35
  class: outerClassNames,
36
36
  });
37
37
  // create a thumb
38
- this._thumb = vevet_dom_1.createElement('div', {
38
+ this._thumb = (0, vevet_dom_1.createElement)('div', {
39
39
  parent: this._outer,
40
- class: prefix + "__thumb " + prefix + "__thumb_" + dir,
40
+ class: "".concat(prefix, "__thumb ").concat(prefix, "__thumb_").concat(dir),
41
41
  });
42
42
  // set auto hide classes
43
43
  if (autoHide) {
@@ -153,11 +153,14 @@ var Bar = /** @class */ (function () {
153
153
  Bar.prototype._setEvents = function () {
154
154
  var _this = this;
155
155
  // set hover events
156
- this._listeners.push(vevet_dom_1.addEventListener(this.outer, 'mouseenter', this._handleHover.bind(this, true)));
157
- this._listeners.push(vevet_dom_1.addEventListener(this.outer, 'mouseleave', this._handleHover.bind(this, false)));
156
+ this._listeners.push((0, vevet_dom_1.addEventListener)(this.outer, 'mouseenter', this._handleHover.bind(this, true)));
157
+ this._listeners.push((0, vevet_dom_1.addEventListener)(this.outer, 'mouseleave', this._handleHover.bind(this, false)));
158
158
  // set scroll events
159
- this._scrollEvent = onScroll_1.default(this.prop.container, function (data) {
160
- _this._handleScroll(data);
159
+ this._scrollEvent = (0, onScroll_1.default)({
160
+ container: this.prop.container,
161
+ callback: function (data) {
162
+ _this._handleScroll(data);
163
+ },
161
164
  });
162
165
  // set dragger
163
166
  if (this.prop.isDraggable) {
@@ -263,12 +266,12 @@ var Bar = /** @class */ (function () {
263
266
  */
264
267
  Bar.prototype._renderThumb = function () {
265
268
  // calculate progress
266
- var progress = boundVal_1.default(this._scrollVal / this.scrollLine, [0, 1]);
269
+ var progress = (0, clamp_1.default)(this._scrollVal / this.scrollLine, [0, 1]);
267
270
  // calculate transforms
268
271
  var x = this.isX ? (this._outerWidth - this._thumbWidth) * progress : 0;
269
272
  var y = this.isY ? (this._outerHeight - this._thumbHeight) * progress : 0;
270
273
  // render the thumb
271
- this._thumb.style.transform = "translate(" + x + "px, " + y + "px)";
274
+ this._thumb.style.transform = "translate(".concat(x, "px, ").concat(y, "px)");
272
275
  };
273
276
  /**
274
277
  * Resize the scene
@@ -282,12 +285,12 @@ var Bar = /** @class */ (function () {
282
285
  // calculate thumb sizes
283
286
  if (this.prop.autoSize) {
284
287
  if (this.isX) {
285
- var barSize = boundVal_1.default(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
286
- thumb.style.width = barSize + "px";
288
+ var barSize = (0, clamp_1.default)(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
289
+ thumb.style.width = "".concat(barSize, "px");
287
290
  }
288
291
  else {
289
- var barSize = boundVal_1.default(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
290
- thumb.style.height = barSize + "px";
292
+ var barSize = (0, clamp_1.default)(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
293
+ thumb.style.height = "".concat(barSize, "px");
291
294
  }
292
295
  }
293
296
  // get thumb sizes