vevet 2.0.1-dev.5 → 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 (128) 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 +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 +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 +65 -25
  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 -5
  34. package/build/cjs/utils/math/scoped.js +18 -0
  35. package/build/cjs/utils/math/spreadScope.js +18 -0
  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 +20 -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 +64 -25
  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 -3
  55. package/build/es/utils/math/scoped.js +14 -0
  56. package/build/es/utils/math/spreadScope.js +15 -0
  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 +13 -5
  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 -3
  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 +23 -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 +105 -34
  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 -4
  111. package/src/ts/utils/math/scoped.ts +17 -0
  112. package/src/ts/utils/math/spreadScope.ts +18 -0
  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/src/ts/utils/math/scopeProgress.ts +0 -23
@@ -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();
@@ -6,7 +6,7 @@ import { Component, NComponent } from '../../../base/Component';
6
6
  import { RequiredModuleProp } from '../../../utils/types/utility';
7
7
  import { AnimationFrame } from '../../animation-frame/AnimationFrame';
8
8
  import { ScrollableElement } from '../types';
9
- import boundVal from '../../../utils/math/boundVal';
9
+ import clamp from '../../../utils/math/clamp';
10
10
  import { NCallbacks } from '../../../base/Callbacks';
11
11
  import { lerp } from '../../../utils/math';
12
12
 
@@ -41,6 +41,10 @@ export namespace NSmoothScroll {
41
41
  * @default false
42
42
  */
43
43
  animationFrame?: false | AnimationFrame;
44
+ /**
45
+ * @default 0
46
+ */
47
+ resizeTimeout?: number;
44
48
  }
45
49
 
46
50
  /**
@@ -215,7 +219,7 @@ export class SmoothScroll <
215
219
  ? -this.prop.overscroll.max : 0;
216
220
  const max = this.maxScrollableWidth
217
221
  + (!!this.prop.overscroll && this.prop.isHorizontal ? this.prop.overscroll.max : 0);
218
- this._targetLeft = boundVal(
222
+ this._targetLeft = clamp(
219
223
  val,
220
224
  [min, max],
221
225
  );
@@ -247,7 +251,7 @@ export class SmoothScroll <
247
251
  ? -this.prop.overscroll.max : 0;
248
252
  const max = this.maxScrollableHeight
249
253
  + (!!this.prop.overscroll && !this.prop.isHorizontal ? this.prop.overscroll.max : 0);
250
- this._targetTop = boundVal(
254
+ this._targetTop = clamp(
251
255
  val,
252
256
  [min, max],
253
257
  );
@@ -401,9 +405,11 @@ export class SmoothScroll <
401
405
  }
402
406
  this._elementsLength = this._elements.length;
403
407
  // add will-change
404
- this._elements.forEach((el) => {
405
- el.style.willChange = 'transform';
406
- });
408
+ if (this.prop.useWillChange) {
409
+ this._elements.forEach((el) => {
410
+ el.style.willChange = 'transform';
411
+ });
412
+ }
407
413
 
408
414
  // initialize the class
409
415
  if (init) {
@@ -423,6 +429,7 @@ export class SmoothScroll <
423
429
  enabled: true,
424
430
  animationFrame: false,
425
431
  recalculateSizes: true,
432
+ resizeTimeout: 0,
426
433
  useWheel: true,
427
434
  autoStop: true,
428
435
  isHorizontal: false,
@@ -453,6 +460,8 @@ export class SmoothScroll <
453
460
  this.resize();
454
461
  this.addViewportCallback('', () => {
455
462
  this.resize(true);
463
+ }, {
464
+ timeout: this.prop.resizeTimeout,
456
465
  });
457
466
 
458
467
  // wheel
@@ -490,8 +499,8 @@ export class SmoothScroll <
490
499
  // get sizes
491
500
  this._clientWidth = outer.clientWidth;
492
501
  this._clientHeight = outer.clientHeight;
493
- this._scrollWidth = boundVal(container.clientWidth, [this.clientWidth, Infinity]);
494
- this._scrollHeight = boundVal(container.clientHeight, [this.clientHeight, Infinity]);
502
+ this._scrollWidth = clamp(container.clientWidth, [this.clientWidth, Infinity]);
503
+ this._scrollHeight = clamp(container.clientHeight, [this.clientHeight, Infinity]);
495
504
 
496
505
  // force instant change
497
506
  // it means that after resizing, scrolling will be instantaneous for a while
@@ -1,4 +1,5 @@
1
1
  import { createElement, selectOne } from 'vevet-dom';
2
+ import { NViewport } from '../../app/events/Viewport';
2
3
  import { Component, NComponent } from '../../base/Component';
3
4
  import { RequiredModuleProp } from '../../utils/types/utility';
4
5
 
@@ -25,6 +26,15 @@ export namespace NSplitText {
25
26
  * @default false
26
27
  */
27
28
  appendLines?: boolean;
29
+ /**
30
+ * Viewport resize event target
31
+ * @default ''
32
+ */
33
+ viewportTarget?: keyof NViewport.CallbacksTypes;
34
+ /**
35
+ * @default 0
36
+ */
37
+ resizeTimeout?: number;
28
38
  }
29
39
 
30
40
  /**
@@ -84,6 +94,8 @@ export class SplitText <
84
94
  container: `#${this.prefix}`,
85
95
  appendLetters: true,
86
96
  appendLines: false,
97
+ viewportTarget: '',
98
+ resizeTimeout: 0,
87
99
  };
88
100
  }
89
101
 
@@ -153,8 +165,12 @@ export class SplitText <
153
165
 
154
166
  // get initial text
155
167
  this._initHTML = this._container.innerHTML;
156
- this._initText = (this._container.innerText || 'no rendered text').trim();
168
+ const innerText = this._container.innerText.trim() || this._container.innerHTML.trim();
169
+ this._initText = innerText || 'no rendered text';
157
170
  this._initText = this._initText.replace(/\s+\n/gm, '\n');
171
+ this._initText = this._initText.replace(/<br>/gm, String.fromCharCode(10));
172
+ this._initText = this._initText.replace(/<br\/>/gm, String.fromCharCode(10));
173
+ this._initText = this._initText.replace(/<br \/>/gm, String.fromCharCode(10));
158
174
 
159
175
  // set default vars
160
176
  this._isPrimarySplit = false;
@@ -174,8 +190,10 @@ export class SplitText <
174
190
  // split the text
175
191
  this.splitText();
176
192
  if (this.prop.appendLines) {
177
- this.addViewportCallback('', () => {
193
+ this.addViewportCallback(this.prop.viewportTarget, () => {
178
194
  this.splitText();
195
+ }, {
196
+ timeout: this.prop.resizeTimeout,
179
197
  });
180
198
  }
181
199
  }
@@ -228,6 +246,7 @@ export class SplitText <
228
246
  // get type of the char
229
247
  const charCode = char.charCodeAt(0);
230
248
  const isWhitespace = charCode === 32 || charCode === 160;
249
+ const isSeparator = [45, 8208, 8211, 8212, 8722].includes(charCode);
231
250
  const isNewLine = charCode === 10;
232
251
 
233
252
  // add elements
@@ -251,6 +270,23 @@ export class SplitText <
251
270
  if (!this.prop.appendLetters) {
252
271
  currentWord.el.innerHTML = currentWord.content;
253
272
  }
273
+
274
+ // go to next word if needed
275
+ if (isSeparator) {
276
+ wordIndex += 1;
277
+ }
278
+ });
279
+
280
+ // only filled words
281
+ this._words = this._words.filter((word, index) => {
282
+ if (word.content.length === 0) {
283
+ if (index > 0) {
284
+ this._words[index - 1].whitespace = word.whitespace;
285
+ this._words[index - 1].br = word.br;
286
+ }
287
+ return false;
288
+ }
289
+ return true;
254
290
  });
255
291
  }
256
292
 
@@ -2,8 +2,8 @@ import easingProgress from 'easing-progress';
2
2
  import { NApplication } from '../../app/Application';
3
3
  import { Component, NComponent } from '../../base/Component';
4
4
  import { RequiredModuleProp } from '../../utils/types/utility';
5
- import scopeProgress from '../../utils/math/scopeProgress';
6
- import boundVal from '../../utils/math/boundVal';
5
+ import scoped from '../../utils/math/scoped';
6
+ import clamp from '../../utils/math/clamp';
7
7
 
8
8
 
9
9
 
@@ -174,8 +174,8 @@ export class StaticTimeline <
174
174
  for (let index = 0, l = length; index < l; index += 1) {
175
175
  const tm = this._nestedTimelines[index];
176
176
  // calculate progress of this very timeline
177
- const tmProgress = boundVal(
178
- scopeProgress(progressForNested, tm.prop.nestedScope),
177
+ const tmProgress = clamp(
178
+ scoped(progressForNested, tm.prop.nestedScope),
179
179
  [0, 1],
180
180
  );
181
181
  tm.progress = tmProgress;