vevet 2.0.1-dev.8 → 2.0.6

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 (134) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/app/Application.js +12 -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 +21 -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 +47 -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/app/Application.js +4 -0
  38. package/build/es/base/Module.js +2 -4
  39. package/build/es/components/animation-frame/AnimationFrame.js +2 -2
  40. package/build/es/components/canvas/Ctx2D.js +6 -2
  41. package/build/es/components/canvas/Ctx2DPrerender.js +20 -2
  42. package/build/es/components/loading/ProgressPreloader.js +14 -2
  43. package/build/es/components/page/Page.js +32 -8
  44. package/build/es/components/scroll/scrollable/ScrollView.js +112 -62
  45. package/build/es/components/scroll/scrollbar/Bar.js +9 -6
  46. package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
  47. package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +13 -9
  48. package/build/es/components/text/SplitText.js +38 -3
  49. package/build/es/components/timeline/StaticTimeline.js +3 -3
  50. package/build/es/components/timeline/Timeline.js +2 -2
  51. package/build/es/utils/listeners/onScroll.js +65 -28
  52. package/build/es/utils/math/{boundVal.js → clamp.js} +2 -2
  53. package/build/es/utils/math/clampScope.js +8 -0
  54. package/build/es/utils/math/inScope.js +6 -0
  55. package/build/es/utils/math/index.js +7 -4
  56. package/build/es/utils/math/scoped.js +14 -0
  57. package/build/es/utils/math/{spreadScopeProgress.js → spreadScope.js} +1 -1
  58. package/build/es/utils/math/wrap.js +10 -0
  59. package/build/types/app/Application.d.ts +1 -0
  60. package/build/types/app/Application.d.ts.map +1 -1
  61. package/build/types/base/Module.d.ts.map +1 -1
  62. package/build/types/components/canvas/Ctx2D.d.ts +9 -0
  63. package/build/types/components/canvas/Ctx2D.d.ts.map +1 -1
  64. package/build/types/components/canvas/Ctx2DPrerender.d.ts +1 -1
  65. package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -1
  66. package/build/types/components/loading/ProgressPreloader.d.ts +7 -0
  67. package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
  68. package/build/types/components/page/Page.d.ts +2 -0
  69. package/build/types/components/page/Page.d.ts.map +1 -1
  70. package/build/types/components/scroll/scrollable/ScrollView.d.ts +40 -14
  71. package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
  72. package/build/types/components/scroll/scrollbar/Bar.d.ts.map +1 -1
  73. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts +4 -0
  74. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts.map +1 -1
  75. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts +4 -0
  76. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts.map +1 -1
  77. package/build/types/components/text/SplitText.d.ts +10 -0
  78. package/build/types/components/text/SplitText.d.ts.map +1 -1
  79. package/build/types/utils/listeners/onScroll.d.ts +10 -6
  80. package/build/types/utils/listeners/onScroll.d.ts.map +1 -1
  81. package/build/types/utils/math/clamp.d.ts +5 -0
  82. package/build/types/utils/math/clamp.d.ts.map +1 -0
  83. package/build/types/utils/math/clampScope.d.ts +5 -0
  84. package/build/types/utils/math/clampScope.d.ts.map +1 -0
  85. package/build/types/utils/math/inScope.d.ts +5 -0
  86. package/build/types/utils/math/inScope.d.ts.map +1 -0
  87. package/build/types/utils/math/index.d.ts +7 -4
  88. package/build/types/utils/math/index.d.ts.map +1 -1
  89. package/build/types/utils/math/scoped.d.ts +12 -0
  90. package/build/types/utils/math/scoped.d.ts.map +1 -0
  91. package/build/types/utils/math/spreadScope.d.ts +5 -0
  92. package/build/types/utils/math/spreadScope.d.ts.map +1 -0
  93. package/build/types/utils/math/wrap.d.ts +5 -0
  94. package/build/types/utils/math/wrap.d.ts.map +1 -0
  95. package/package.json +3 -3
  96. package/src/ts/app/Application.ts +6 -0
  97. package/src/ts/base/Module.ts +5 -4
  98. package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
  99. package/src/ts/components/canvas/Ctx2D.ts +16 -1
  100. package/src/ts/components/canvas/Ctx2DPrerender.ts +23 -6
  101. package/src/ts/components/loading/ProgressPreloader.ts +21 -2
  102. package/src/ts/components/page/Page.ts +34 -8
  103. package/src/ts/components/scroll/scrollable/ScrollView.ts +155 -86
  104. package/src/ts/components/scroll/scrollbar/Bar.ts +9 -6
  105. package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
  106. package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +17 -8
  107. package/src/ts/components/text/SplitText.ts +52 -2
  108. package/src/ts/components/timeline/StaticTimeline.ts +4 -4
  109. package/src/ts/components/timeline/Timeline.ts +2 -2
  110. package/src/ts/utils/listeners/onScroll.ts +101 -38
  111. package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
  112. package/src/ts/utils/math/clampScope.ts +16 -0
  113. package/src/ts/utils/math/inScope.ts +9 -0
  114. package/src/ts/utils/math/index.ts +12 -6
  115. package/src/ts/utils/math/scoped.ts +17 -0
  116. package/src/ts/utils/math/{spreadScopeProgress.ts → spreadScope.ts} +2 -2
  117. package/src/ts/utils/math/wrap.ts +18 -0
  118. package/build/cjs/components/scroll/custom-scroll/CustomScroll.js +0 -517
  119. package/build/cjs/components/split-text/SplitText.js +0 -233
  120. package/build/cjs/utils/math/scopeProgress.js +0 -25
  121. package/build/es/components/scroll/custom-scroll/CustomScroll.js +0 -486
  122. package/build/es/components/split-text/SplitText.js +0 -199
  123. package/build/es/utils/math/scopeProgress.js +0 -22
  124. package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts +0 -322
  125. package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts.map +0 -1
  126. package/build/types/components/split-text/SplitText.d.ts +0 -118
  127. package/build/types/components/split-text/SplitText.d.ts.map +0 -1
  128. package/build/types/utils/math/boundVal.d.ts +0 -5
  129. package/build/types/utils/math/boundVal.d.ts.map +0 -1
  130. package/build/types/utils/math/scopeProgress.d.ts +0 -20
  131. package/build/types/utils/math/scopeProgress.d.ts.map +0 -1
  132. package/build/types/utils/math/spreadScopeProgress.d.ts +0 -5
  133. package/build/types/utils/math/spreadScopeProgress.d.ts.map +0 -1
  134. package/src/ts/utils/math/scopeProgress.ts +0 -23
@@ -52,6 +52,11 @@ export class Page <
52
52
  ChangeableProp,
53
53
  CallbacksTypes
54
54
  > {
55
+ protected _blocked: boolean;
56
+ protected get blocked () {
57
+ return this._blocked;
58
+ }
59
+
55
60
  /**
56
61
  * If the page is created
57
62
  */
@@ -95,6 +100,7 @@ export class Page <
95
100
  super(initialProp, false);
96
101
 
97
102
  // set default vars
103
+ this._blocked = false;
98
104
  this._created = false;
99
105
  this._shown = false;
100
106
  this._hidden = false;
@@ -129,11 +135,12 @@ export class Page <
129
135
  resolve, reject,
130
136
  ) => {
131
137
  this.canCreate().then(() => {
132
- if (this.created) {
138
+ if (this.created || this.blocked) {
139
+ reject();
133
140
  return;
134
141
  }
135
142
  // update vars
136
- this._created = true;
143
+ this._blocked = true;
137
144
  this._shown = false;
138
145
  this._hidden = false;
139
146
  this._destroyed = false;
@@ -147,7 +154,11 @@ export class Page <
147
154
  // actions
148
155
  this._create().then(() => {
149
156
  this.callbacks.tbt('create', false);
157
+ this._blocked = false;
158
+ this._created = true;
150
159
  resolve();
160
+ }).catch(() => {
161
+ reject();
151
162
  });
152
163
  }).catch(() => {
153
164
  reject();
@@ -191,19 +202,24 @@ export class Page <
191
202
  resolve, reject,
192
203
  ) => {
193
204
  this.canShow().then(() => {
194
- if (this.shown) {
205
+ if (this.shown || this.blocked) {
206
+ reject();
195
207
  return;
196
208
  }
197
209
  // update vars
210
+ this._blocked = true;
198
211
  this._created = true;
199
- this._shown = true;
200
212
  this._hidden = false;
201
213
  this._destroyed = false;
202
214
 
203
215
  // actions
204
216
  this._show().then(() => {
205
217
  this.callbacks.tbt('show', false);
218
+ this._blocked = false;
219
+ this._shown = true;
206
220
  resolve();
221
+ }).catch(() => {
222
+ reject();
207
223
  });
208
224
  // launch events
209
225
  }).catch(() => {
@@ -249,19 +265,24 @@ export class Page <
249
265
  reject: (...arg: any) => void,
250
266
  ) => {
251
267
  this.canHide().then(() => {
252
- if (this.hidden) {
268
+ if (this.hidden || this.blocked) {
269
+ reject();
253
270
  return;
254
271
  }
255
272
  // update vars
273
+ this._blocked = true;
256
274
  this._created = true;
257
275
  this._shown = false;
258
- this._hidden = true;
259
276
  this._destroyed = false;
260
277
 
261
278
  // actions
262
279
  this._hide().then(() => {
263
280
  this.callbacks.tbt('hide', false);
281
+ this._blocked = false;
282
+ this._hidden = true;
264
283
  resolve();
284
+ }).catch(() => {
285
+ reject();
265
286
  });
266
287
  }).catch(() => {
267
288
  reject();
@@ -306,14 +327,15 @@ export class Page <
306
327
  reject: (...arg: any) => void,
307
328
  ) => {
308
329
  this.canDestroy().then(() => {
309
- if (this.destroyed) {
330
+ if (this.destroyed || this.blocked) {
331
+ reject();
310
332
  return;
311
333
  }
312
334
  // change vars
335
+ this._blocked = true;
313
336
  this._created = false;
314
337
  this._shown = false;
315
338
  this._hidden = true;
316
- this._destroyed = true;
317
339
 
318
340
  // update page
319
341
  this._app.page = false;
@@ -322,7 +344,11 @@ export class Page <
322
344
 
323
345
  // actions
324
346
  this._destroy().then(() => {
347
+ this._blocked = false;
348
+ this._destroyed = true;
325
349
  resolve();
350
+ }).catch(() => {
351
+ reject();
326
352
  });
327
353
  }).catch(() => {
328
354
  reject();
@@ -1,10 +1,9 @@
1
- import { selectAll, SelectorAll } from 'vevet-dom';
2
1
  import { ScrollEventsBase, NScrollEventsBase } from './ScrollEventsBase';
3
2
  import { IRemovable } from '../../../utils/types/general';
4
3
  import { RequiredModuleProp } from '../../../utils/types/utility';
5
4
  import onScroll from '../../../utils/listeners/onScroll';
6
5
  import { intersectionObserverSupported } from '../../../utils/listeners';
7
- import boundVal from '../../../utils/math/boundVal';
6
+ import clamp from '../../../utils/math/clamp';
8
7
  import timeoutCallback from '../../../utils/common/timeoutCallback';
9
8
 
10
9
 
@@ -16,10 +15,17 @@ export namespace NScrollView {
16
15
  */
17
16
  export interface StaticProp extends NScrollEventsBase.StaticProp {
18
17
  /**
19
- * Elements to seek
20
- * @default '.v-scroll-view__el'
18
+ * If enabled, scrolling events will be created.
19
+ * You can use "false" to create just an instance of the ScrollView
20
+ * and later enable animations.
21
+ * @default true
22
+ */
23
+ enabled?: boolean;
24
+ /**
25
+ * View elements.
26
+ * @default []
21
27
  */
22
- elements?: SelectorAll;
28
+ elements?: Element[];
23
29
  /**
24
30
  * The moment at which the element is considered to be in the viewport.
25
31
  * The value is calculated from top to bottom or from left to right.
@@ -49,6 +55,10 @@ export namespace NScrollView {
49
55
  * @default true
50
56
  */
51
57
  useIntersectionObserver?: boolean;
58
+ /**
59
+ * @default 0
60
+ */
61
+ resizeTimeout?: number;
52
62
  }
53
63
 
54
64
  /**
@@ -96,13 +106,15 @@ export class ScrollView <
96
106
  > (): T {
97
107
  return {
98
108
  ...super._getDefaultProp(),
109
+ enabled: true,
99
110
  container: window,
100
- elements: `.${this.prefix}__el`,
111
+ elements: [],
101
112
  threshold: 0.9,
102
113
  states: 'in',
103
114
  classToToggle: 'viewed',
104
115
  useDelay: false,
105
116
  useIntersectionObserver: true,
117
+ resizeTimeout: 0,
106
118
  };
107
119
  }
108
120
 
@@ -113,15 +125,27 @@ export class ScrollView <
113
125
  */
114
126
  protected _scrollEvent?: IRemovable;
115
127
  /**
116
- * Intersection observer
128
+ * Intersection observer - type IN
117
129
  */
118
- protected _intersectionObserver?: IntersectionObserver;
130
+ protected _intersectionObserverIn?: IntersectionObserver;
131
+ /**
132
+ * Intersection observer - type OUT
133
+ */
134
+ protected _intersectionObserverOut?: IntersectionObserver;
119
135
 
120
136
  /**
121
137
  * If first start
122
138
  */
123
139
  protected _firstStart: boolean;
124
140
 
141
+ protected _elements: NScrollView.El[];
142
+ /**
143
+ * Elements to seek
144
+ */
145
+ get elements () {
146
+ return this._elements;
147
+ }
148
+
125
149
 
126
150
 
127
151
  constructor (
@@ -131,11 +155,10 @@ export class ScrollView <
131
155
  super(initialProp, false);
132
156
 
133
157
  this._scrollEvent = undefined;
134
- this._intersectionObserver = undefined;
158
+ this._intersectionObserverIn = undefined;
159
+ this._intersectionObserverOut = undefined;
135
160
  this._firstStart = true;
136
-
137
- // get view elements
138
- this.updateElements();
161
+ this._elements = [...this.prop.elements];
139
162
 
140
163
  // initialize the class
141
164
  if (init) {
@@ -145,7 +168,6 @@ export class ScrollView <
145
168
 
146
169
  public init () {
147
170
  super.init();
148
- this.seekBounding();
149
171
  }
150
172
 
151
173
  // Set Module Events
@@ -154,14 +176,14 @@ export class ScrollView <
154
176
  this.resize();
155
177
  this.addViewportCallback('', () => {
156
178
  this.resize();
179
+ }, {
180
+ timeout: this.prop.resizeTimeout,
157
181
  });
158
182
  }
159
183
 
160
184
  protected _onPropMutate () {
161
185
  super._onPropMutate();
162
- this._removeViewEvents();
163
- this.updateElements();
164
- this._setViewEvents();
186
+ this.resize();
165
187
  }
166
188
 
167
189
  /**
@@ -169,7 +191,10 @@ export class ScrollView <
169
191
  */
170
192
  public resize () {
171
193
  this._removeViewEvents();
172
- this._setViewEvents();
194
+ if (this.prop.enabled) {
195
+ this._setViewEvents();
196
+ this.seekBounding();
197
+ }
173
198
  }
174
199
 
175
200
  /**
@@ -184,24 +209,37 @@ export class ScrollView <
184
209
  ? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
185
210
  const yMargin = this._firstStart
186
211
  ? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
187
- // create intersection observer
188
- this._intersectionObserver = new IntersectionObserver(
189
- this._handleIntersectionObserver.bind(this),
212
+ // create intersection observers
213
+ this._intersectionObserverIn = new IntersectionObserver(
214
+ this._handleIntersectionObserverIn.bind(this),
190
215
  {
191
216
  root: this.intersectionRoot,
192
217
  threshold: 0,
193
218
  rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
194
219
  },
195
220
  );
196
- // add elements
197
- if (this.elements) {
221
+ this.elements.forEach((el) => {
222
+ this._intersectionObserverIn?.observe(el);
223
+ });
224
+ if (this.prop.states === 'inout') {
225
+ this._intersectionObserverOut = new IntersectionObserver(
226
+ this._handleIntersectionObserverOut.bind(this),
227
+ {
228
+ root: this.intersectionRoot,
229
+ threshold: 0,
230
+ rootMargin: '0px 0px 0px 0px',
231
+ },
232
+ );
198
233
  this.elements.forEach((el) => {
199
- this._intersectionObserver?.observe(el);
234
+ this._intersectionObserverOut?.observe(el);
200
235
  });
201
236
  }
202
237
  } else {
203
238
  // set scroll bounding events
204
- this._scrollEvent = onScroll(this.prop.container, this._handleScroll.bind(this));
239
+ this._scrollEvent = onScroll({
240
+ container: this.prop.container,
241
+ callback: this._handleScroll.bind(this),
242
+ });
205
243
  }
206
244
  }
207
245
 
@@ -214,57 +252,17 @@ export class ScrollView <
214
252
  this._scrollEvent.remove();
215
253
  this._scrollEvent = undefined;
216
254
  }
217
- // destroy intersection observer
218
- if (this._intersectionObserver) {
219
- this._intersectionObserver.disconnect();
220
- this._intersectionObserver = undefined;
221
- }
222
- }
223
-
224
-
225
-
226
- protected _elements!: NScrollView.El[];
227
- /**
228
- * Element to seek
229
- */
230
- get elements () {
231
- return this._elements;
232
- }
233
-
234
- /**
235
- * Update elements
236
- */
237
- public updateElements () {
238
- // check if elements exist
239
- if (typeof this.elements === 'undefined') {
240
- this._elements = [];
241
- }
242
- // unobserve old elements
243
- this.elements.forEach((el) => {
244
- if (this._intersectionObserver) {
245
- this._intersectionObserver.unobserve(el);
246
- }
247
- });
248
- // update elements
249
- this._elements = Array.from(
250
- selectAll(this.prop.elements as any, this.domParent || undefined),
251
- ).filter(
252
- (el) => !el.classList.contains(this.prop.classToToggle),
253
- );
254
- // add them to the observer
255
- this._elements.forEach((el) => {
256
- if (this._intersectionObserver) {
257
- this._intersectionObserver.observe(el);
258
- }
259
- });
255
+ // destroy intersection observers
256
+ this._intersectionObserverIn?.disconnect();
257
+ this._intersectionObserverIn = undefined;
258
+ this._intersectionObserverOut?.disconnect();
259
+ this._intersectionObserverOut = undefined;
260
260
  }
261
261
 
262
-
263
-
264
262
  /**
265
263
  * Event on IntersectionObserver
266
264
  */
267
- protected _handleIntersectionObserver (
265
+ protected _handleIntersectionObserverIn (
268
266
  data: IntersectionObserverEntry[],
269
267
  ) {
270
268
  const parentBounding = this._firstStart ? this.scrollContainerBounding : false;
@@ -274,11 +272,13 @@ export class ScrollView <
274
272
  if (this._firstStart && !!parentBounding && entry.isIntersecting) {
275
273
  delay = this._elementInViewportData(entry.target, parentBounding).delay;
276
274
  }
277
- this._handleInOut(
278
- entry.target,
279
- entry.isIntersecting,
280
- delay,
281
- );
275
+ if (entry.isIntersecting) {
276
+ this._handleInOut(
277
+ entry.target,
278
+ entry.isIntersecting,
279
+ delay,
280
+ );
281
+ }
282
282
  }
283
283
  this._processUnusedElements();
284
284
  // change states
@@ -288,6 +288,24 @@ export class ScrollView <
288
288
  }
289
289
  }
290
290
 
291
+ /**
292
+ * Event on IntersectionObserver
293
+ */
294
+ protected _handleIntersectionObserverOut (
295
+ data: IntersectionObserverEntry[],
296
+ ) {
297
+ for (let index = 0; index < data.length; index += 1) {
298
+ const entry = data[index];
299
+ if (!entry.isIntersecting) {
300
+ this._handleInOut(
301
+ entry.target,
302
+ entry.isIntersecting,
303
+ 0,
304
+ );
305
+ }
306
+ }
307
+ }
308
+
291
309
  /**
292
310
  * Event on Scroll
293
311
  */
@@ -313,7 +331,9 @@ export class ScrollView <
313
331
  const el = this.elements[index];
314
332
  const elData = this._elementInViewportData(el, scrollContainerBounding);
315
333
  const delay = elData.isIntersecting ? elData.delay : 0;
316
- this._handleInOut(el, elData.isIntersecting, delay);
334
+ if (typeof elData.isIntersecting === 'boolean') {
335
+ this._handleInOut(el, elData.isIntersecting, delay);
336
+ }
317
337
  }
318
338
  this._processUnusedElements();
319
339
 
@@ -335,7 +355,7 @@ export class ScrollView <
335
355
  const bounding = el.getBoundingClientRect();
336
356
 
337
357
  // check if the element is intersecting
338
- let isIntersecting = false;
358
+ let isIntersecting: undefined | boolean;
339
359
  if (
340
360
  bounding.top < parentBounding.top + parentBounding.height * threshold
341
361
  && bounding.left < parentBounding.left + parentBounding.width * threshold
@@ -350,13 +370,18 @@ export class ScrollView <
350
370
  } else {
351
371
  isIntersecting = true;
352
372
  }
373
+ } else if (
374
+ bounding.top > parentBounding.top + parentBounding.height
375
+ || bounding.left > parentBounding.left + parentBounding.width
376
+ ) {
377
+ isIntersecting = false;
353
378
  }
354
379
 
355
380
  // calculate delay only if it is enabled & calculations
356
381
  // are done for the first time
357
382
  let delay = 0;
358
383
  if (!!useDelay && this._firstStart) {
359
- const progress = boundVal(
384
+ const progress = clamp(
360
385
  useDelay.dir === 'x'
361
386
  ? (bounding.left - parentBounding.left) / parentBounding.width
362
387
  : (bounding.top - parentBounding.top) / parentBounding.height,
@@ -371,8 +396,6 @@ export class ScrollView <
371
396
  };
372
397
  }
373
398
 
374
-
375
-
376
399
  /**
377
400
  * Event that is triggered when an element appears or disappears
378
401
  */
@@ -393,9 +416,11 @@ export class ScrollView <
393
416
  el.scrollViewIn = inViewport;
394
417
 
395
418
  // toggle classes
396
- timeoutCallback(() => {
397
- el.classList.toggle(this.prop.classToToggle, inViewport);
398
- }, delay);
419
+ if (this.prop.classToToggle) {
420
+ timeoutCallback(() => {
421
+ el.classList.toggle(this.prop.classToToggle, inViewport);
422
+ }, delay);
423
+ }
399
424
 
400
425
  // process callbacks
401
426
  if (inViewport && (states === 'in' || states === 'inout')) {
@@ -419,14 +444,58 @@ export class ScrollView <
419
444
  // remove unused elements
420
445
  const elementsToRemove = this._elements.filter((el) => el.scrollViewIn);
421
446
  elementsToRemove.forEach((el) => {
422
- if (this._intersectionObserver) {
423
- this._intersectionObserver.unobserve(el);
424
- }
447
+ this._intersectionObserverIn?.unobserve(el);
448
+ this._intersectionObserverOut?.unobserve(el);
425
449
  });
426
450
  this._elements = this._elements.filter((el) => !el.scrollViewIn);
427
451
  }
428
452
 
429
453
 
454
+ /**
455
+ * Add a view element
456
+ */
457
+ public addElement (
458
+ element: Element,
459
+ ): IRemovable {
460
+ const viewEl = element as NScrollView.El;
461
+ viewEl.scrollViewIn = undefined;
462
+ this._elements.push(element);
463
+ this._intersectionObserverIn?.observe(element);
464
+ this._intersectionObserverOut?.observe(element);
465
+ if (this.prop.enabled) {
466
+ this.seekBounding();
467
+ }
468
+ return {
469
+ remove: () => {
470
+ this.removeElement(element);
471
+ },
472
+ };
473
+ }
474
+
475
+ /**
476
+ * Remove a view element
477
+ */
478
+ public removeElement (
479
+ element: Element,
480
+ ) {
481
+ const viewEl = element as NScrollView.El;
482
+ viewEl.scrollViewIn = undefined;
483
+ this._elements = this._elements.filter((el) => el !== element);
484
+ this._intersectionObserverIn?.unobserve(element);
485
+ this._intersectionObserverOut?.unobserve(element);
486
+ }
487
+
488
+ /**
489
+ * Remove all view elements
490
+ */
491
+ public removeElements () {
492
+ this._elements.forEach((el) => {
493
+ this.removeElement(el);
494
+ });
495
+ this._elements = [];
496
+ }
497
+
498
+
430
499
 
431
500
  /**
432
501
  * Destroy the module
@@ -1,7 +1,7 @@
1
1
  import { addEventListener, createElement, IAddEventListener } from 'vevet-dom';
2
2
  import { IRemovable } from '../../../utils/types/general';
3
3
  import onScroll from '../../../utils/listeners/onScroll';
4
- import boundVal from '../../../utils/math/boundVal';
4
+ import clamp from '../../../utils/math/clamp';
5
5
  import { DraggerMove, NDraggerMove } from '../../dragger/DraggerMove';
6
6
  import { SmoothScroll } from '../smooth-scroll/SmoothScroll';
7
7
 
@@ -163,8 +163,11 @@ export default class Bar {
163
163
  this._listeners.push(addEventListener(this.outer, 'mouseleave', this._handleHover.bind(this, false)));
164
164
 
165
165
  // set scroll events
166
- this._scrollEvent = onScroll(this.prop.container, (data) => {
167
- this._handleScroll(data);
166
+ this._scrollEvent = onScroll({
167
+ container: this.prop.container,
168
+ callback: (data) => {
169
+ this._handleScroll(data);
170
+ },
168
171
  });
169
172
 
170
173
  // set dragger
@@ -290,7 +293,7 @@ export default class Bar {
290
293
  */
291
294
  protected _renderThumb () {
292
295
  // calculate progress
293
- const progress = boundVal(
296
+ const progress = clamp(
294
297
  this._scrollVal / this.scrollLine,
295
298
  [0, 1],
296
299
  );
@@ -318,7 +321,7 @@ export default class Bar {
318
321
  // calculate thumb sizes
319
322
  if (this.prop.autoSize) {
320
323
  if (this.isX) {
321
- const barSize = boundVal(
324
+ const barSize = clamp(
322
325
  this._outerWidth / (this.scrollWidth / (
323
326
  this.scrollWidth - scrollLine
324
327
  )),
@@ -326,7 +329,7 @@ export default class Bar {
326
329
  );
327
330
  thumb.style.width = `${barSize}px`;
328
331
  } else {
329
- const barSize = boundVal(
332
+ const barSize = clamp(
330
333
  this._outerHeight / (this.scrollHeight / (
331
334
  this.scrollHeight - scrollLine
332
335
  )),
@@ -50,6 +50,10 @@ export namespace NScrollBar {
50
50
  * @default false
51
51
  */
52
52
  optimizeCalculations?: boolean;
53
+ /**
54
+ * @default 0
55
+ */
56
+ resizeTimeout?: number;
53
57
  /**
54
58
  * If the scroll bar is draggable
55
59
  * @default true
@@ -101,6 +105,7 @@ export class ScrollBar <
101
105
  autoHide: true,
102
106
  minSize: 50,
103
107
  optimizeCalculations: false,
108
+ resizeTimeout: 0,
104
109
  isDraggable: true,
105
110
  draggableScrollBehavior: 'smooth',
106
111
  };
@@ -245,6 +250,8 @@ export class ScrollBar <
245
250
  } else {
246
251
  this.addViewportCallback('', () => {
247
252
  this.resize();
253
+ }, {
254
+ timeout: this.prop.resizeTimeout,
248
255
  });
249
256
  }
250
257
  this.resize();