vevet 2.0.1-dev.3 → 2.0.1-dev.30

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 (125) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/base/Module.js +13 -4
  3. package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
  4. package/build/cjs/components/canvas/Ctx2D.js +6 -2
  5. package/build/cjs/components/canvas/Ctx2DPrerender.js +20 -2
  6. package/build/cjs/components/loading/ProgressPreloader.js +14 -2
  7. package/build/cjs/components/page/Page.js +36 -8
  8. package/build/cjs/components/scroll/plugins/SmoothScrollDragPlugin.js +40 -5
  9. package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +9 -0
  10. package/build/cjs/components/scroll/scrollable/ScrollView.js +124 -66
  11. package/build/cjs/components/scroll/scrollbar/Bar.js +12 -6
  12. package/build/cjs/components/scroll/scrollbar/ScrollBar.js +3 -1
  13. package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +19 -9
  14. package/build/cjs/components/text/SplitText.js +25 -3
  15. package/build/cjs/components/timeline/StaticTimeline.js +3 -3
  16. package/build/cjs/components/timeline/Timeline.js +3 -2
  17. package/build/cjs/handlers/wheel/WheelHandler.js +195 -0
  18. package/build/cjs/index.js +3 -1
  19. package/build/cjs/utils/listeners/onScroll.js +65 -25
  20. package/build/cjs/utils/math/clamp.js +16 -0
  21. package/build/cjs/utils/math/clampScope.js +16 -0
  22. package/build/cjs/utils/math/inScope.js +10 -0
  23. package/build/cjs/utils/math/index.js +13 -5
  24. package/build/cjs/utils/math/scoped.js +18 -0
  25. package/build/cjs/utils/math/spreadScope.js +18 -0
  26. package/build/cjs/utils/math/spreadScopeProgress.js +18 -0
  27. package/build/cjs/utils/math/wrap.js +13 -0
  28. package/build/es/base/Module.js +2 -4
  29. package/build/es/components/animation-frame/AnimationFrame.js +2 -2
  30. package/build/es/components/canvas/Ctx2D.js +6 -2
  31. package/build/es/components/canvas/Ctx2DPrerender.js +20 -2
  32. package/build/es/components/loading/ProgressPreloader.js +14 -2
  33. package/build/es/components/page/Page.js +32 -8
  34. package/build/es/components/scroll/plugins/SmoothScrollDragPlugin.js +40 -5
  35. package/build/es/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +9 -0
  36. package/build/es/components/scroll/scrollable/ScrollView.js +113 -61
  37. package/build/es/components/scroll/scrollbar/Bar.js +12 -6
  38. package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
  39. package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +19 -9
  40. package/build/es/components/text/SplitText.js +25 -3
  41. package/build/es/components/timeline/StaticTimeline.js +3 -3
  42. package/build/es/components/timeline/Timeline.js +3 -2
  43. package/build/es/handlers/wheel/WheelHandler.js +153 -0
  44. package/build/es/index.js +2 -1
  45. package/build/es/utils/listeners/onScroll.js +64 -25
  46. package/build/es/utils/math/clamp.js +12 -0
  47. package/build/es/utils/math/clampScope.js +8 -0
  48. package/build/es/utils/math/inScope.js +6 -0
  49. package/build/es/utils/math/index.js +7 -3
  50. package/build/es/utils/math/scoped.js +14 -0
  51. package/build/es/utils/math/spreadScope.js +15 -0
  52. package/build/es/utils/math/spreadScopeProgress.js +15 -0
  53. package/build/es/utils/math/wrap.js +10 -0
  54. package/build/types/base/Module.d.ts.map +1 -1
  55. package/build/types/components/canvas/Ctx2D.d.ts +9 -0
  56. package/build/types/components/canvas/Ctx2D.d.ts.map +1 -1
  57. package/build/types/components/canvas/Ctx2DPrerender.d.ts +1 -1
  58. package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -1
  59. package/build/types/components/loading/ProgressPreloader.d.ts +7 -0
  60. package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
  61. package/build/types/components/page/Page.d.ts +2 -0
  62. package/build/types/components/page/Page.d.ts.map +1 -1
  63. package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts +11 -0
  64. package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts.map +1 -1
  65. package/build/types/components/scroll/plugins/SmoothScrollKeyboardPlugin.d.ts.map +1 -1
  66. package/build/types/components/scroll/scrollable/ScrollView.d.ts +40 -14
  67. package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
  68. package/build/types/components/scroll/scrollbar/Bar.d.ts.map +1 -1
  69. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts +4 -0
  70. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts.map +1 -1
  71. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts +4 -0
  72. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts.map +1 -1
  73. package/build/types/components/text/SplitText.d.ts +10 -0
  74. package/build/types/components/text/SplitText.d.ts.map +1 -1
  75. package/build/types/components/timeline/Timeline.d.ts.map +1 -1
  76. package/build/types/handlers/wheel/WheelHandler.d.ts +100 -0
  77. package/build/types/handlers/wheel/WheelHandler.d.ts.map +1 -0
  78. package/build/types/index.d.ts +2 -1
  79. package/build/types/index.d.ts.map +1 -1
  80. package/build/types/utils/listeners/onScroll.d.ts +13 -5
  81. package/build/types/utils/listeners/onScroll.d.ts.map +1 -1
  82. package/build/types/utils/math/clamp.d.ts +5 -0
  83. package/build/types/utils/math/clamp.d.ts.map +1 -0
  84. package/build/types/utils/math/clampScope.d.ts +5 -0
  85. package/build/types/utils/math/clampScope.d.ts.map +1 -0
  86. package/build/types/utils/math/inScope.d.ts +5 -0
  87. package/build/types/utils/math/inScope.d.ts.map +1 -0
  88. package/build/types/utils/math/index.d.ts +7 -3
  89. package/build/types/utils/math/index.d.ts.map +1 -1
  90. package/build/types/utils/math/scoped.d.ts +12 -0
  91. package/build/types/utils/math/scoped.d.ts.map +1 -0
  92. package/build/types/utils/math/spreadScope.d.ts +5 -0
  93. package/build/types/utils/math/spreadScope.d.ts.map +1 -0
  94. package/build/types/utils/math/spreadScopeProgress.d.ts +5 -0
  95. package/build/types/utils/math/spreadScopeProgress.d.ts.map +1 -0
  96. package/build/types/utils/math/wrap.d.ts +5 -0
  97. package/build/types/utils/math/wrap.d.ts.map +1 -0
  98. package/package.json +3 -2
  99. package/src/sass/components/cursor/_custom-cursor.scss +0 -1
  100. package/src/ts/base/Module.ts +5 -4
  101. package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
  102. package/src/ts/components/canvas/Ctx2D.ts +16 -1
  103. package/src/ts/components/canvas/Ctx2DPrerender.ts +23 -6
  104. package/src/ts/components/loading/ProgressPreloader.ts +21 -2
  105. package/src/ts/components/page/Page.ts +34 -8
  106. package/src/ts/components/scroll/plugins/SmoothScrollDragPlugin.ts +58 -5
  107. package/src/ts/components/scroll/plugins/SmoothScrollKeyboardPlugin.ts +12 -0
  108. package/src/ts/components/scroll/scrollable/ScrollView.ts +157 -85
  109. package/src/ts/components/scroll/scrollbar/Bar.ts +12 -6
  110. package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
  111. package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +24 -8
  112. package/src/ts/components/text/SplitText.ts +38 -2
  113. package/src/ts/components/timeline/StaticTimeline.ts +4 -4
  114. package/src/ts/components/timeline/Timeline.ts +3 -2
  115. package/src/ts/handlers/wheel/WheelHandler.ts +269 -0
  116. package/src/ts/index.ts +4 -0
  117. package/src/ts/utils/listeners/onScroll.ts +105 -34
  118. package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
  119. package/src/ts/utils/math/clampScope.ts +16 -0
  120. package/src/ts/utils/math/inScope.ts +9 -0
  121. package/src/ts/utils/math/index.ts +12 -4
  122. package/src/ts/utils/math/scoped.ts +17 -0
  123. package/src/ts/utils/math/spreadScope.ts +18 -0
  124. package/src/ts/utils/math/wrap.ts +18 -0
  125. package/src/ts/utils/math/scopeProgress.ts +0 -23
@@ -25,16 +25,20 @@ 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) {
29
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
30
+ to[j] = from[i];
31
+ return to;
32
+ };
28
33
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
34
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
35
  };
31
36
  Object.defineProperty(exports, "__esModule", { value: true });
32
37
  exports.ScrollView = void 0;
33
- var vevet_dom_1 = require("vevet-dom");
34
38
  var ScrollEventsBase_1 = require("./ScrollEventsBase");
35
39
  var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
36
40
  var listeners_1 = require("../../../utils/listeners");
37
- var boundVal_1 = __importDefault(require("../../../utils/math/boundVal"));
41
+ var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
38
42
  var timeoutCallback_1 = __importDefault(require("../../../utils/common/timeoutCallback"));
39
43
  /**
40
44
  * Elements into viewport
@@ -44,9 +48,11 @@ var ScrollView = /** @class */ (function (_super) {
44
48
  function ScrollView(initialProp, init) {
45
49
  if (init === void 0) { init = true; }
46
50
  var _this = _super.call(this, initialProp, false) || this;
51
+ _this._scrollEvent = undefined;
52
+ _this._intersectionObserverIn = undefined;
53
+ _this._intersectionObserverOut = undefined;
47
54
  _this._firstStart = true;
48
- // get view elements
49
- _this.updateElements();
55
+ _this._elements = __spreadArray([], _this.prop.elements);
50
56
  // initialize the class
51
57
  if (init) {
52
58
  _this.init();
@@ -61,11 +67,20 @@ var ScrollView = /** @class */ (function (_super) {
61
67
  configurable: true
62
68
  });
63
69
  ScrollView.prototype._getDefaultProp = function () {
64
- 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 });
70
+ 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 });
65
71
  };
72
+ Object.defineProperty(ScrollView.prototype, "elements", {
73
+ /**
74
+ * Elements to seek
75
+ */
76
+ get: function () {
77
+ return this._elements;
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
66
82
  ScrollView.prototype.init = function () {
67
83
  _super.prototype.init.call(this);
68
- this.seekBounding();
69
84
  };
70
85
  // Set Module Events
71
86
  ScrollView.prototype._setEvents = function () {
@@ -74,20 +89,23 @@ var ScrollView = /** @class */ (function (_super) {
74
89
  this.resize();
75
90
  this.addViewportCallback('', function () {
76
91
  _this.resize();
92
+ }, {
93
+ timeout: this.prop.resizeTimeout,
77
94
  });
78
95
  };
79
96
  ScrollView.prototype._onPropMutate = function () {
80
97
  _super.prototype._onPropMutate.call(this);
81
- this._removeViewEvents();
82
- this.updateElements();
83
- this._setViewEvents();
98
+ this.resize();
84
99
  };
85
100
  /**
86
101
  * Resize the scene
87
102
  */
88
103
  ScrollView.prototype.resize = function () {
89
104
  this._removeViewEvents();
90
- this._setViewEvents();
105
+ if (this.prop.enabled) {
106
+ this._setViewEvents();
107
+ this.seekBounding();
108
+ }
91
109
  };
92
110
  /**
93
111
  * Set View events: scroll or intersection
@@ -102,78 +120,56 @@ var ScrollView = /** @class */ (function (_super) {
102
120
  ? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
103
121
  var yMargin = this._firstStart
104
122
  ? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
105
- // create intersection observer
106
- this._intersectionObserver = new IntersectionObserver(this._handleIntersectionObserver.bind(this), {
123
+ // create intersection observers
124
+ this._intersectionObserverIn = new IntersectionObserver(this._handleIntersectionObserverIn.bind(this), {
107
125
  root: this.intersectionRoot,
108
126
  threshold: 0,
109
127
  rootMargin: "0px " + xMargin + "px " + yMargin + "px 0px",
110
128
  });
111
- // add elements
112
- if (this.elements) {
129
+ this.elements.forEach(function (el) {
130
+ var _a;
131
+ (_a = _this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(el);
132
+ });
133
+ if (this.prop.states === 'inout') {
134
+ this._intersectionObserverOut = new IntersectionObserver(this._handleIntersectionObserverOut.bind(this), {
135
+ root: this.intersectionRoot,
136
+ threshold: 0,
137
+ rootMargin: '0px 0px 0px 0px',
138
+ });
113
139
  this.elements.forEach(function (el) {
114
140
  var _a;
115
- (_a = _this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
141
+ (_a = _this._intersectionObserverOut) === null || _a === void 0 ? void 0 : _a.observe(el);
116
142
  });
117
143
  }
118
144
  }
119
145
  else {
120
146
  // set scroll bounding events
121
- this._scrollEvent = onScroll_1.default(this.prop.container, this._handleScroll.bind(this));
147
+ this._scrollEvent = onScroll_1.default({
148
+ container: this.prop.container,
149
+ callback: this._handleScroll.bind(this),
150
+ });
122
151
  }
123
152
  };
124
153
  /**
125
154
  * Remove View events: scroll or intersection
126
155
  */
127
156
  ScrollView.prototype._removeViewEvents = function () {
157
+ var _a, _b;
128
158
  // remove scroll events
129
159
  if (this._scrollEvent) {
130
160
  this._scrollEvent.remove();
131
161
  this._scrollEvent = undefined;
132
162
  }
133
- // destroy intersection observer
134
- if (this._intersectionObserver) {
135
- this._intersectionObserver.disconnect();
136
- this._intersectionObserver = undefined;
137
- }
138
- };
139
- Object.defineProperty(ScrollView.prototype, "elements", {
140
- /**
141
- * Element to seek
142
- */
143
- get: function () {
144
- return this._elements;
145
- },
146
- enumerable: false,
147
- configurable: true
148
- });
149
- /**
150
- * Update elements
151
- */
152
- ScrollView.prototype.updateElements = function () {
153
- var _this = this;
154
- // check if elements exist
155
- if (typeof this.elements === 'undefined') {
156
- this._elements = [];
157
- }
158
- // unobserve old elements
159
- this.elements.forEach(function (el) {
160
- if (_this._intersectionObserver) {
161
- _this._intersectionObserver.unobserve(el);
162
- }
163
- });
164
- // update elements
165
- this._elements = Array.from(vevet_dom_1.selectAll(this.prop.elements, this.domParent || undefined)).filter(function (el) { return !el.classList.contains(_this.prop.classToToggle); });
166
- // add them to the observer
167
- this._elements.forEach(function (el) {
168
- if (_this._intersectionObserver) {
169
- _this._intersectionObserver.observe(el);
170
- }
171
- });
163
+ // destroy intersection observers
164
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.disconnect();
165
+ this._intersectionObserverIn = undefined;
166
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.disconnect();
167
+ this._intersectionObserverOut = undefined;
172
168
  };
173
169
  /**
174
170
  * Event on IntersectionObserver
175
171
  */
176
- ScrollView.prototype._handleIntersectionObserver = function (data) {
172
+ ScrollView.prototype._handleIntersectionObserverIn = function (data) {
177
173
  var parentBounding = this._firstStart ? this.scrollContainerBounding : false;
178
174
  for (var index = 0; index < data.length; index += 1) {
179
175
  var entry = data[index];
@@ -181,7 +177,9 @@ var ScrollView = /** @class */ (function (_super) {
181
177
  if (this._firstStart && !!parentBounding && entry.isIntersecting) {
182
178
  delay = this._elementInViewportData(entry.target, parentBounding).delay;
183
179
  }
184
- this._handleInOut(entry.target, entry.isIntersecting, delay);
180
+ if (entry.isIntersecting) {
181
+ this._handleInOut(entry.target, entry.isIntersecting, delay);
182
+ }
185
183
  }
186
184
  this._processUnusedElements();
187
185
  // change states
@@ -190,6 +188,17 @@ var ScrollView = /** @class */ (function (_super) {
190
188
  this.resize();
191
189
  }
192
190
  };
191
+ /**
192
+ * Event on IntersectionObserver
193
+ */
194
+ ScrollView.prototype._handleIntersectionObserverOut = function (data) {
195
+ for (var index = 0; index < data.length; index += 1) {
196
+ var entry = data[index];
197
+ if (!entry.isIntersecting) {
198
+ this._handleInOut(entry.target, entry.isIntersecting, 0);
199
+ }
200
+ }
201
+ };
193
202
  /**
194
203
  * Event on Scroll
195
204
  */
@@ -212,7 +221,9 @@ var ScrollView = /** @class */ (function (_super) {
212
221
  var el = this.elements[index];
213
222
  var elData = this._elementInViewportData(el, scrollContainerBounding);
214
223
  var delay = elData.isIntersecting ? elData.delay : 0;
215
- this._handleInOut(el, elData.isIntersecting, delay);
224
+ if (typeof elData.isIntersecting === 'boolean') {
225
+ this._handleInOut(el, elData.isIntersecting, delay);
226
+ }
216
227
  }
217
228
  this._processUnusedElements();
218
229
  // change states
@@ -228,7 +239,7 @@ var ScrollView = /** @class */ (function (_super) {
228
239
  var threshold = this._firstStart ? 1 : propThreshold;
229
240
  var bounding = el.getBoundingClientRect();
230
241
  // check if the element is intersecting
231
- var isIntersecting = false;
242
+ var isIntersecting;
232
243
  if (bounding.top < parentBounding.top + parentBounding.height * threshold
233
244
  && bounding.left < parentBounding.left + parentBounding.width * threshold) {
234
245
  if (states === 'in') {
@@ -242,11 +253,15 @@ var ScrollView = /** @class */ (function (_super) {
242
253
  isIntersecting = true;
243
254
  }
244
255
  }
256
+ else if (bounding.top > parentBounding.top + parentBounding.height
257
+ || bounding.left > parentBounding.left + parentBounding.width) {
258
+ isIntersecting = false;
259
+ }
245
260
  // calculate delay only if it is enabled & calculations
246
261
  // are done for the first time
247
262
  var delay = 0;
248
263
  if (!!useDelay && this._firstStart) {
249
- var progress = boundVal_1.default(useDelay.dir === 'x'
264
+ var progress = clamp_1.default(useDelay.dir === 'x'
250
265
  ? (bounding.left - parentBounding.left) / parentBounding.width
251
266
  : (bounding.top - parentBounding.top) / parentBounding.height, [0, 1]);
252
267
  delay = progress * useDelay.max;
@@ -271,9 +286,11 @@ var ScrollView = /** @class */ (function (_super) {
271
286
  // update props
272
287
  el.scrollViewIn = inViewport;
273
288
  // toggle classes
274
- timeoutCallback_1.default(function () {
275
- el.classList.toggle(_this.prop.classToToggle, inViewport);
276
- }, delay);
289
+ if (this.prop.classToToggle) {
290
+ timeoutCallback_1.default(function () {
291
+ el.classList.toggle(_this.prop.classToToggle, inViewport);
292
+ }, delay);
293
+ }
277
294
  // process callbacks
278
295
  if (inViewport && (states === 'in' || states === 'inout')) {
279
296
  timeoutCallback_1.default(function () {
@@ -297,12 +314,53 @@ var ScrollView = /** @class */ (function (_super) {
297
314
  // remove unused elements
298
315
  var elementsToRemove = this._elements.filter(function (el) { return el.scrollViewIn; });
299
316
  elementsToRemove.forEach(function (el) {
300
- if (_this._intersectionObserver) {
301
- _this._intersectionObserver.unobserve(el);
302
- }
317
+ var _a, _b;
318
+ (_a = _this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(el);
319
+ (_b = _this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(el);
303
320
  });
304
321
  this._elements = this._elements.filter(function (el) { return !el.scrollViewIn; });
305
322
  };
323
+ /**
324
+ * Add a view element
325
+ */
326
+ ScrollView.prototype.addElement = function (element) {
327
+ var _this = this;
328
+ var _a, _b;
329
+ var viewEl = element;
330
+ viewEl.scrollViewIn = undefined;
331
+ this._elements.push(element);
332
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.observe(element);
333
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.observe(element);
334
+ if (this.prop.enabled) {
335
+ this.seekBounding();
336
+ }
337
+ return {
338
+ remove: function () {
339
+ _this.removeElement(element);
340
+ },
341
+ };
342
+ };
343
+ /**
344
+ * Remove a view element
345
+ */
346
+ ScrollView.prototype.removeElement = function (element) {
347
+ var _a, _b;
348
+ var viewEl = element;
349
+ viewEl.scrollViewIn = undefined;
350
+ this._elements = this._elements.filter(function (el) { return el !== element; });
351
+ (_a = this._intersectionObserverIn) === null || _a === void 0 ? void 0 : _a.unobserve(element);
352
+ (_b = this._intersectionObserverOut) === null || _b === void 0 ? void 0 : _b.unobserve(element);
353
+ };
354
+ /**
355
+ * Remove all view elements
356
+ */
357
+ ScrollView.prototype.removeElements = function () {
358
+ var _this = this;
359
+ this._elements.forEach(function (el) {
360
+ _this.removeElement(el);
361
+ });
362
+ this._elements = [];
363
+ };
306
364
  /**
307
365
  * Destroy the module
308
366
  */
@@ -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 () {
@@ -22,6 +22,9 @@ var Bar = /** @class */ (function () {
22
22
  left: 0,
23
23
  top: 0,
24
24
  };
25
+ this._scrollEvent = undefined;
26
+ this._actionTimeout = undefined;
27
+ this._dragger = undefined;
25
28
  // create outer
26
29
  var outerClassNames = prefix + " " + prefix + "_" + dir;
27
30
  if (container instanceof Window) {
@@ -153,8 +156,11 @@ var Bar = /** @class */ (function () {
153
156
  this._listeners.push(vevet_dom_1.addEventListener(this.outer, 'mouseenter', this._handleHover.bind(this, true)));
154
157
  this._listeners.push(vevet_dom_1.addEventListener(this.outer, 'mouseleave', this._handleHover.bind(this, false)));
155
158
  // set scroll events
156
- this._scrollEvent = onScroll_1.default(this.prop.container, function (data) {
157
- _this._handleScroll(data);
159
+ this._scrollEvent = onScroll_1.default({
160
+ container: this.prop.container,
161
+ callback: function (data) {
162
+ _this._handleScroll(data);
163
+ },
158
164
  });
159
165
  // set dragger
160
166
  if (this.prop.isDraggable) {
@@ -260,7 +266,7 @@ var Bar = /** @class */ (function () {
260
266
  */
261
267
  Bar.prototype._renderThumb = function () {
262
268
  // calculate progress
263
- var progress = boundVal_1.default(this._scrollVal / this.scrollLine, [0, 1]);
269
+ var progress = clamp_1.default(this._scrollVal / this.scrollLine, [0, 1]);
264
270
  // calculate transforms
265
271
  var x = this.isX ? (this._outerWidth - this._thumbWidth) * progress : 0;
266
272
  var y = this.isY ? (this._outerHeight - this._thumbHeight) * progress : 0;
@@ -279,11 +285,11 @@ var Bar = /** @class */ (function () {
279
285
  // calculate thumb sizes
280
286
  if (this.prop.autoSize) {
281
287
  if (this.isX) {
282
- var barSize = boundVal_1.default(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
288
+ var barSize = clamp_1.default(this._outerWidth / (this.scrollWidth / (this.scrollWidth - scrollLine)), [minSize, Infinity]);
283
289
  thumb.style.width = barSize + "px";
284
290
  }
285
291
  else {
286
- var barSize = boundVal_1.default(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
292
+ var barSize = clamp_1.default(this._outerHeight / (this.scrollHeight / (this.scrollHeight - scrollLine)), [minSize, Infinity]);
287
293
  thumb.style.height = barSize + "px";
288
294
  }
289
295
  }
@@ -91,7 +91,7 @@ var ScrollBar = /** @class */ (function (_super) {
91
91
  return _this;
92
92
  }
93
93
  ScrollBar.prototype._getDefaultProp = function () {
94
- return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, domParent: false, draggable: true, autoSize: true, autoHide: true, minSize: 50, optimizeCalculations: false, isDraggable: true, draggableScrollBehavior: 'smooth' });
94
+ return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, domParent: false, draggable: true, autoSize: true, autoHide: true, minSize: 50, optimizeCalculations: false, resizeTimeout: 0, isDraggable: true, draggableScrollBehavior: 'smooth' });
95
95
  };
96
96
  Object.defineProperty(ScrollBar.prototype, "prefix", {
97
97
  get: function () {
@@ -167,6 +167,8 @@ var ScrollBar = /** @class */ (function (_super) {
167
167
  else {
168
168
  this.addViewportCallback('', function () {
169
169
  _this.resize();
170
+ }, {
171
+ timeout: this.prop.resizeTimeout,
170
172
  });
171
173
  }
172
174
  this.resize();
@@ -34,7 +34,7 @@ var vevet_dom_1 = require("vevet-dom");
34
34
  var normalize_wheel_1 = __importDefault(require("normalize-wheel"));
35
35
  var Component_1 = require("../../../base/Component");
36
36
  var AnimationFrame_1 = require("../../animation-frame/AnimationFrame");
37
- var boundVal_1 = __importDefault(require("../../../utils/math/boundVal"));
37
+ var clamp_1 = __importDefault(require("../../../utils/math/clamp"));
38
38
  var math_1 = require("../../../utils/math");
39
39
  /**
40
40
  * Create smooth scrolling.
@@ -55,6 +55,8 @@ var SmoothScroll = /** @class */ (function (_super) {
55
55
  _this._clientWidth = 0;
56
56
  _this._clientHeight = 0;
57
57
  _this._instant = false;
58
+ _this._animationFrame = undefined;
59
+ _this._outerAnimationFrameEvent = undefined;
58
60
  _this._currentFPS = 60;
59
61
  // get outer elements
60
62
  _this._outer = vevet_dom_1.selectOne(selectors.outer);
@@ -85,9 +87,11 @@ var SmoothScroll = /** @class */ (function (_super) {
85
87
  }
86
88
  _this._elementsLength = _this._elements.length;
87
89
  // add will-change
88
- _this._elements.forEach(function (el) {
89
- el.style.willChange = 'transform';
90
- });
90
+ if (_this.prop.useWillChange) {
91
+ _this._elements.forEach(function (el) {
92
+ el.style.willChange = 'transform';
93
+ });
94
+ }
91
95
  // initialize the class
92
96
  if (init) {
93
97
  _this.init();
@@ -145,7 +149,7 @@ var SmoothScroll = /** @class */ (function (_super) {
145
149
  ? -this.prop.overscroll.max : 0;
146
150
  var max = this.maxScrollableWidth
147
151
  + (!!this.prop.overscroll && this.prop.isHorizontal ? this.prop.overscroll.max : 0);
148
- this._targetLeft = boundVal_1.default(val, [min, max]);
152
+ this._targetLeft = clamp_1.default(val, [min, max]);
149
153
  },
150
154
  enumerable: false,
151
155
  configurable: true
@@ -173,7 +177,7 @@ var SmoothScroll = /** @class */ (function (_super) {
173
177
  ? -this.prop.overscroll.max : 0;
174
178
  var max = this.maxScrollableHeight
175
179
  + (!!this.prop.overscroll && !this.prop.isHorizontal ? this.prop.overscroll.max : 0);
176
- this._targetTop = boundVal_1.default(val, [min, max]);
180
+ this._targetTop = clamp_1.default(val, [min, max]);
177
181
  },
178
182
  enumerable: false,
179
183
  configurable: true
@@ -254,7 +258,7 @@ var SmoothScroll = /** @class */ (function (_super) {
254
258
  return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { selectors: {
255
259
  outer: "#" + this.prefix,
256
260
  elements: false,
257
- }, enabled: true, animationFrame: false, recalculateSizes: true, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
261
+ }, enabled: true, animationFrame: false, recalculateSizes: true, resizeTimeout: 0, useWheel: true, autoStop: true, isHorizontal: false, stopPropagation: true, useWillChange: true, render: {
258
262
  lerp: 0.1,
259
263
  lerpToFixed: 2,
260
264
  approximation: 0.1,
@@ -276,6 +280,8 @@ var SmoothScroll = /** @class */ (function (_super) {
276
280
  this.resize();
277
281
  this.addViewportCallback('', function () {
278
282
  _this.resize(true);
283
+ }, {
284
+ timeout: this.prop.resizeTimeout,
279
285
  });
280
286
  // wheel
281
287
  this.addEventListeners(this.outer, 'wheel', function (e) {
@@ -306,8 +312,8 @@ var SmoothScroll = /** @class */ (function (_super) {
306
312
  // get sizes
307
313
  this._clientWidth = outer.clientWidth;
308
314
  this._clientHeight = outer.clientHeight;
309
- this._scrollWidth = boundVal_1.default(container.clientWidth, [this.clientWidth, Infinity]);
310
- this._scrollHeight = boundVal_1.default(container.clientHeight, [this.clientHeight, Infinity]);
315
+ this._scrollWidth = clamp_1.default(container.clientWidth, [this.clientWidth, Infinity]);
316
+ this._scrollHeight = clamp_1.default(container.clientHeight, [this.clientHeight, Infinity]);
311
317
  // force instant change
312
318
  // it means that after resizing, scrolling will be instantaneous for a while
313
319
  if (native) {
@@ -320,6 +326,10 @@ var SmoothScroll = /** @class */ (function (_super) {
320
326
  this.targetLeft = parseInt(this.targetLeft.toFixed(0), 10);
321
327
  this.targetTop = parseInt(this.targetTop.toFixed(0), 10);
322
328
  }
329
+ // set scroll classes
330
+ var hasScroll = this.maxScrollableHeight > 0 || this.maxScrollableWidth > 0;
331
+ outer.classList.toggle('has-scroll', hasScroll);
332
+ outer.classList.toggle('no-scroll', !hasScroll);
323
333
  // render elements
324
334
  this._updateElementsProp();
325
335
  // this.render();
@@ -50,8 +50,12 @@ var SplitText = /** @class */ (function (_super) {
50
50
  }
51
51
  // get initial text
52
52
  _this._initHTML = _this._container.innerHTML;
53
- _this._initText = (_this._container.innerText || 'no rendered text').trim();
53
+ var innerText = _this._container.innerText.trim() || _this._container.innerHTML.trim();
54
+ _this._initText = innerText || 'no rendered text';
54
55
  _this._initText = _this._initText.replace(/\s+\n/gm, '\n');
56
+ _this._initText = _this._initText.replace(/<br>/gm, String.fromCharCode(10));
57
+ _this._initText = _this._initText.replace(/<br\/>/gm, String.fromCharCode(10));
58
+ _this._initText = _this._initText.replace(/<br \/>/gm, String.fromCharCode(10));
55
59
  // set default vars
56
60
  _this._isPrimarySplit = false;
57
61
  _this._letters = [];
@@ -64,7 +68,7 @@ var SplitText = /** @class */ (function (_super) {
64
68
  return _this;
65
69
  }
66
70
  SplitText.prototype._getDefaultProp = function () {
67
- return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: "#" + this.prefix, appendLetters: true, appendLines: false });
71
+ return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: "#" + this.prefix, appendLetters: true, appendLines: false, viewportTarget: '', resizeTimeout: 0 });
68
72
  };
69
73
  Object.defineProperty(SplitText.prototype, "prefix", {
70
74
  get: function () {
@@ -110,8 +114,10 @@ var SplitText = /** @class */ (function (_super) {
110
114
  // split the text
111
115
  this.splitText();
112
116
  if (this.prop.appendLines) {
113
- this.addViewportCallback('', function () {
117
+ this.addViewportCallback(this.prop.viewportTarget, function () {
114
118
  _this.splitText();
119
+ }, {
120
+ timeout: this.prop.resizeTimeout,
115
121
  });
116
122
  }
117
123
  };
@@ -157,6 +163,7 @@ var SplitText = /** @class */ (function (_super) {
157
163
  // get type of the char
158
164
  var charCode = char.charCodeAt(0);
159
165
  var isWhitespace = charCode === 32 || charCode === 160;
166
+ var isSeparator = [45, 8208, 8211, 8212, 8722].includes(charCode);
160
167
  var isNewLine = charCode === 10;
161
168
  // add elements
162
169
  if (isWhitespace) {
@@ -177,6 +184,21 @@ var SplitText = /** @class */ (function (_super) {
177
184
  if (!_this.prop.appendLetters) {
178
185
  currentWord.el.innerHTML = currentWord.content;
179
186
  }
187
+ // go to next word if needed
188
+ if (isSeparator) {
189
+ wordIndex += 1;
190
+ }
191
+ });
192
+ // only filled words
193
+ this._words = this._words.filter(function (word, index) {
194
+ if (word.content.length === 0) {
195
+ if (index > 0) {
196
+ _this._words[index - 1].whitespace = word.whitespace;
197
+ _this._words[index - 1].br = word.br;
198
+ }
199
+ return false;
200
+ }
201
+ return true;
180
202
  });
181
203
  };
182
204
  /**
@@ -32,8 +32,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.StaticTimeline = void 0;
33
33
  var easing_progress_1 = __importDefault(require("easing-progress"));
34
34
  var Component_1 = require("../../base/Component");
35
- var scopeProgress_1 = __importDefault(require("../../utils/math/scopeProgress"));
36
- var boundVal_1 = __importDefault(require("../../utils/math/boundVal"));
35
+ var scoped_1 = __importDefault(require("../../utils/math/scoped"));
36
+ var clamp_1 = __importDefault(require("../../utils/math/clamp"));
37
37
  /**
38
38
  * StaticTimeline is the base class for Timeline itself.
39
39
  * The difference between the coponents is that StaticTimeline has no animation:
@@ -118,7 +118,7 @@ var StaticTimeline = /** @class */ (function (_super) {
118
118
  for (var index = 0, l = length; index < l; index += 1) {
119
119
  var tm = this._nestedTimelines[index];
120
120
  // calculate progress of this very timeline
121
- var tmProgress = boundVal_1.default(scopeProgress_1.default(progressForNested, tm.prop.nestedScope), [0, 1]);
121
+ var tmProgress = clamp_1.default(scoped_1.default(progressForNested, tm.prop.nestedScope), [0, 1]);
122
122
  tm.progress = tmProgress;
123
123
  }
124
124
  };
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.Timeline = void 0;
33
33
  var StaticTimeline_1 = require("./StaticTimeline");
34
- var boundVal_1 = __importDefault(require("../../utils/math/boundVal"));
34
+ var clamp_1 = __importDefault(require("../../utils/math/clamp"));
35
35
  /**
36
36
  * Timeline is an animation helper.
37
37
  */
@@ -44,6 +44,7 @@ var Timeline = /** @class */ (function (_super) {
44
44
  _this._isPlaying = false;
45
45
  _this._isReversed = false;
46
46
  _this._isPaused = false;
47
+ _this._animationFrame = undefined;
47
48
  _this._animationFrameLastTime = 0;
48
49
  if (init) {
49
50
  _this.init();
@@ -148,7 +149,7 @@ var Timeline = /** @class */ (function (_super) {
148
149
  this._animationFrameLastTime = currentTime;
149
150
  // calculate current progress
150
151
  var progressIterator = frameDiff / this.prop.duration / (isReversed ? -1 : 1);
151
- var progressTarget = boundVal_1.default(this.progress + progressIterator, [0, 1]);
152
+ var progressTarget = clamp_1.default(this.progress + progressIterator, [0, 1]);
152
153
  this.progress = progressTarget;
153
154
  // end animation
154
155
  if ((progressTarget === 1 && !isReversed)