vevet 2.0.1-dev.9 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/app/Application.js +8 -8
  3. package/build/cjs/app/events/PageLoad.js +3 -3
  4. package/build/cjs/app/events/Viewport.js +5 -5
  5. package/build/cjs/base/Callbacks.js +3 -3
  6. package/build/cjs/base/Module.js +16 -7
  7. package/build/cjs/base/MutableProp.js +10 -10
  8. package/build/cjs/components/animation-frame/AnimationFrame.js +1 -1
  9. package/build/cjs/components/canvas/Ctx2D.js +7 -3
  10. package/build/cjs/components/canvas/Ctx2DPrerender.js +17 -3
  11. package/build/cjs/components/cursor/CustomCursor.js +12 -12
  12. package/build/cjs/components/dragger/Dragger.js +8 -8
  13. package/build/cjs/components/dragger/DraggerMove.js +2 -2
  14. package/build/cjs/components/loading/Preloader.js +5 -5
  15. package/build/cjs/components/loading/ProgressPreloader.js +17 -5
  16. package/build/cjs/components/page/Page.js +37 -9
  17. package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +2 -2
  18. package/build/cjs/components/scroll/scrollable/ScrollEventsBase.js +1 -1
  19. package/build/cjs/components/scroll/scrollable/ScrollView.js +133 -73
  20. package/build/cjs/components/scroll/scrollbar/Bar.js +18 -15
  21. package/build/cjs/components/scroll/scrollbar/ScrollBar.js +9 -7
  22. package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +26 -22
  23. package/build/cjs/components/text/SplitText.js +34 -12
  24. package/build/cjs/components/timeline/StaticTimeline.js +4 -4
  25. package/build/cjs/components/timeline/Timeline.js +2 -2
  26. package/build/cjs/handlers/wheel/WheelHandler.js +4 -4
  27. package/build/cjs/utils/common/mergeWithoutArrays.js +1 -1
  28. package/build/cjs/utils/common/randID.js +2 -2
  29. package/build/cjs/utils/listeners/onScroll.js +66 -28
  30. package/build/cjs/utils/math/{boundVal.js → clamp.js} +3 -3
  31. package/build/cjs/utils/math/clampScope.js +16 -0
  32. package/build/cjs/utils/math/inScope.js +10 -0
  33. package/build/cjs/utils/math/index.js +13 -7
  34. package/build/cjs/utils/math/scoped.js +18 -0
  35. package/build/cjs/utils/math/{spreadScopeProgress.js → spreadScope.js} +2 -2
  36. package/build/cjs/utils/math/wrap.js +13 -0
  37. package/build/es/base/Module.js +2 -4
  38. package/build/es/components/animation-frame/AnimationFrame.js +2 -2
  39. package/build/es/components/canvas/Ctx2D.js +6 -2
  40. package/build/es/components/canvas/Ctx2DPrerender.js +16 -2
  41. package/build/es/components/loading/ProgressPreloader.js +14 -2
  42. package/build/es/components/page/Page.js +32 -8
  43. package/build/es/components/scroll/scrollable/ScrollView.js +112 -62
  44. package/build/es/components/scroll/scrollbar/Bar.js +9 -6
  45. package/build/es/components/scroll/scrollbar/ScrollBar.js +3 -1
  46. package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +13 -9
  47. package/build/es/components/text/SplitText.js +25 -3
  48. package/build/es/components/timeline/StaticTimeline.js +3 -3
  49. package/build/es/components/timeline/Timeline.js +2 -2
  50. package/build/es/utils/listeners/onScroll.js +65 -28
  51. package/build/es/utils/math/{boundVal.js → clamp.js} +2 -2
  52. package/build/es/utils/math/clampScope.js +8 -0
  53. package/build/es/utils/math/inScope.js +6 -0
  54. package/build/es/utils/math/index.js +7 -4
  55. package/build/es/utils/math/scoped.js +14 -0
  56. package/build/es/utils/math/{spreadScopeProgress.js → spreadScope.js} +1 -1
  57. package/build/es/utils/math/wrap.js +10 -0
  58. package/build/types/base/Module.d.ts.map +1 -1
  59. package/build/types/components/canvas/Ctx2D.d.ts +9 -0
  60. package/build/types/components/canvas/Ctx2D.d.ts.map +1 -1
  61. package/build/types/components/canvas/Ctx2DPrerender.d.ts +1 -1
  62. package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -1
  63. package/build/types/components/loading/ProgressPreloader.d.ts +7 -0
  64. package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -1
  65. package/build/types/components/page/Page.d.ts +2 -0
  66. package/build/types/components/page/Page.d.ts.map +1 -1
  67. package/build/types/components/scroll/scrollable/ScrollView.d.ts +40 -14
  68. package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -1
  69. package/build/types/components/scroll/scrollbar/Bar.d.ts.map +1 -1
  70. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts +4 -0
  71. package/build/types/components/scroll/scrollbar/ScrollBar.d.ts.map +1 -1
  72. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts +4 -0
  73. package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts.map +1 -1
  74. package/build/types/components/text/SplitText.d.ts +10 -0
  75. package/build/types/components/text/SplitText.d.ts.map +1 -1
  76. package/build/types/utils/listeners/onScroll.d.ts +10 -6
  77. package/build/types/utils/listeners/onScroll.d.ts.map +1 -1
  78. package/build/types/utils/math/clamp.d.ts +5 -0
  79. package/build/types/utils/math/clamp.d.ts.map +1 -0
  80. package/build/types/utils/math/clampScope.d.ts +5 -0
  81. package/build/types/utils/math/clampScope.d.ts.map +1 -0
  82. package/build/types/utils/math/inScope.d.ts +5 -0
  83. package/build/types/utils/math/inScope.d.ts.map +1 -0
  84. package/build/types/utils/math/index.d.ts +7 -4
  85. package/build/types/utils/math/index.d.ts.map +1 -1
  86. package/build/types/utils/math/scoped.d.ts +12 -0
  87. package/build/types/utils/math/scoped.d.ts.map +1 -0
  88. package/build/types/utils/math/spreadScope.d.ts +5 -0
  89. package/build/types/utils/math/spreadScope.d.ts.map +1 -0
  90. package/build/types/utils/math/wrap.d.ts +5 -0
  91. package/build/types/utils/math/wrap.d.ts.map +1 -0
  92. package/package.json +3 -3
  93. package/src/ts/base/Module.ts +5 -4
  94. package/src/ts/components/animation-frame/AnimationFrame.ts +2 -2
  95. package/src/ts/components/canvas/Ctx2D.ts +16 -1
  96. package/src/ts/components/canvas/Ctx2DPrerender.ts +19 -6
  97. package/src/ts/components/loading/ProgressPreloader.ts +21 -2
  98. package/src/ts/components/page/Page.ts +34 -8
  99. package/src/ts/components/scroll/scrollable/ScrollView.ts +155 -86
  100. package/src/ts/components/scroll/scrollbar/Bar.ts +9 -6
  101. package/src/ts/components/scroll/scrollbar/ScrollBar.ts +7 -0
  102. package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +17 -8
  103. package/src/ts/components/text/SplitText.ts +38 -2
  104. package/src/ts/components/timeline/StaticTimeline.ts +4 -4
  105. package/src/ts/components/timeline/Timeline.ts +2 -2
  106. package/src/ts/utils/listeners/onScroll.ts +101 -38
  107. package/src/ts/utils/math/{boundVal.ts → clamp.ts} +3 -3
  108. package/src/ts/utils/math/clampScope.ts +16 -0
  109. package/src/ts/utils/math/inScope.ts +9 -0
  110. package/src/ts/utils/math/index.ts +12 -6
  111. package/src/ts/utils/math/scoped.ts +17 -0
  112. package/src/ts/utils/math/{spreadScopeProgress.ts → spreadScope.ts} +2 -2
  113. package/src/ts/utils/math/wrap.ts +18 -0
  114. package/build/cjs/components/scroll/custom-scroll/CustomScroll.js +0 -517
  115. package/build/cjs/components/split-text/SplitText.js +0 -233
  116. package/build/cjs/utils/math/scopeProgress.js +0 -25
  117. package/build/es/components/scroll/custom-scroll/CustomScroll.js +0 -486
  118. package/build/es/components/split-text/SplitText.js +0 -199
  119. package/build/es/utils/math/scopeProgress.js +0 -22
  120. package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts +0 -322
  121. package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts.map +0 -1
  122. package/build/types/components/split-text/SplitText.d.ts +0 -118
  123. package/build/types/components/split-text/SplitText.d.ts.map +0 -1
  124. package/build/types/utils/math/boundVal.d.ts +0 -5
  125. package/build/types/utils/math/boundVal.d.ts.map +0 -1
  126. package/build/types/utils/math/scopeProgress.d.ts +0 -20
  127. package/build/types/utils/math/scopeProgress.d.ts.map +0 -1
  128. package/build/types/utils/math/spreadScopeProgress.d.ts +0 -5
  129. package/build/types/utils/math/spreadScopeProgress.d.ts.map +0 -1
  130. package/src/ts/utils/math/scopeProgress.ts +0 -23
@@ -1,486 +0,0 @@
1
- import { selectAll, selectOne, isElement, createElement, } from 'vevet-dom';
2
- import normalizeWheel from 'normalize-wheel';
3
- import { Component } from '../../../base/Component';
4
- import { mergeWithoutArrays } from '../../../utils/common';
5
- import { AnimationFrame } from '../../animation-frame/AnimationFrame';
6
- import boundVal from '../../../utils/math/boundVal';
7
- import { lerp } from '../../../utils/math';
8
- /**
9
- * Create smooth scrolling.
10
- */
11
- export class CustomScroll extends Component {
12
- get prefix() {
13
- return `${this._app.prefix}custom-scroll`;
14
- }
15
- /**
16
- * Scroll parent
17
- */
18
- _outer;
19
- get outer() {
20
- return this._outer;
21
- }
22
- /**
23
- * Scroll container. If the element does not exist indide the outer,
24
- * it will be created automatically
25
- */
26
- _container;
27
- get container() {
28
- return this._container;
29
- }
30
- /**
31
- * If the container element existed before the class initialization
32
- */
33
- _containerExists;
34
- /**
35
- * Scrollable elements
36
- */
37
- _elements;
38
- get elements() {
39
- return this._elements;
40
- }
41
- _elementsLength;
42
- /**
43
- * Scroll target value
44
- */
45
- _targetLeft;
46
- get targetLeft() {
47
- return this._targetLeft;
48
- }
49
- set targetLeft(val) {
50
- this.targetLeftDry = val;
51
- this.enable();
52
- }
53
- /**
54
- * Set value without animation request
55
- */
56
- set targetLeftDry(val) {
57
- this._targetLeft = boundVal(val, [0, this.maxScrollableWidth]);
58
- }
59
- get targetLeftDry() {
60
- return this._targetLeft;
61
- }
62
- /**
63
- * Scroll target value
64
- */
65
- _targetTop;
66
- get targetTop() {
67
- return this._targetTop;
68
- }
69
- set targetTop(val) {
70
- this.targetTopDry = val;
71
- this.enable();
72
- }
73
- /**
74
- * Set value without animation request
75
- */
76
- set targetTopDry(val) {
77
- this._targetTop = boundVal(val, [0, this.maxScrollableHeight]);
78
- }
79
- get targetTopDry() {
80
- return this._targetTop;
81
- }
82
- /**
83
- * Scroll left
84
- */
85
- _scrollLeft;
86
- get scrollLeft() {
87
- return this._scrollLeft;
88
- }
89
- set scrollLeft(val) {
90
- this.targetLeftDry = val;
91
- this._scrollLeft = this._targetLeft;
92
- this.enable();
93
- }
94
- /**
95
- * Scroll top
96
- */
97
- _scrollTop;
98
- get scrollTop() {
99
- return this._scrollTop;
100
- }
101
- set scrollTop(val) {
102
- this.targetTopDry = val;
103
- this._scrollTop = this._targetTop;
104
- this.enable();
105
- }
106
- /**
107
- * Scroll width
108
- */
109
- _scrollWidth;
110
- get scrollWidth() {
111
- return this._scrollWidth;
112
- }
113
- /**
114
- * Scroll height
115
- */
116
- _scrollHeight;
117
- get scrollHeight() {
118
- return this._scrollHeight;
119
- }
120
- /**
121
- * Parent width
122
- */
123
- _clientWidth;
124
- get clientWidth() {
125
- return this._clientWidth;
126
- }
127
- /**
128
- * Parent height
129
- */
130
- _clientHeight;
131
- get clientHeight() {
132
- return this._clientHeight;
133
- }
134
- /**
135
- * Maximum scrollable area of the X axis
136
- */
137
- get maxScrollableWidth() {
138
- return this.scrollWidth - this.clientWidth;
139
- }
140
- /**
141
- * Maximum scrollable area of the Y axis
142
- */
143
- get maxScrollableHeight() {
144
- return this.scrollHeight - this.clientHeight;
145
- }
146
- /**
147
- * If the approximation between the target and current scroll values must be instantaneous
148
- */
149
- _instant;
150
- /**
151
- * Inner AnimationFrame.
152
- * The AnimationFrame is not create if an outer AnimationFrame is passed in properties.
153
- */
154
- _animationFrame;
155
- /**
156
- * AnimationFrame callback is used for outer AnimationFrame only.
157
- */
158
- _outerAnimationFrameEvent;
159
- constructor(initialProp = {}, init = true) {
160
- super(initialProp, false);
161
- const { selectors } = this.prop;
162
- // set default variables
163
- this._targetLeft = 0;
164
- this._targetTop = 0;
165
- this._scrollLeft = 0;
166
- this._scrollTop = 0;
167
- this._scrollWidth = 0;
168
- this._scrollHeight = 0;
169
- this._clientWidth = 0;
170
- this._clientHeight = 0;
171
- this._instant = false;
172
- // get outer elements
173
- this._outer = selectOne(selectors.outer);
174
- if (!(this._outer instanceof HTMLElement)) {
175
- throw new Error(`${selectors.outer} is not a HTMLElement`);
176
- }
177
- this._outer.classList.add(this.prefix);
178
- // get or create container
179
- const existingContainer = selectOne(`.${this.prefix}__container`, this.outer);
180
- if (isElement(existingContainer)) {
181
- this._container = existingContainer;
182
- this._containerExists = true;
183
- }
184
- else {
185
- this._container = createElement('div', {
186
- class: `${this.prefix}__container`,
187
- parent: this.outer,
188
- children: Array.from(this.outer.children),
189
- });
190
- this._containerExists = false;
191
- }
192
- // get scrollable elements
193
- if (selectors.elements) {
194
- this._elements = Array.from(selectAll(selectors.elements, this._outer));
195
- }
196
- else {
197
- this._elements = [this._container];
198
- }
199
- this._elementsLength = this._elements.length;
200
- // initialize the class
201
- if (init) {
202
- this.init();
203
- }
204
- }
205
- _getDefaultProp() {
206
- const prop = {
207
- selectors: {
208
- outer: '#v-custom-scroll',
209
- elements: false,
210
- },
211
- enabled: true,
212
- animationFrame: false,
213
- recalculateSizes: true,
214
- useWheel: true,
215
- autoStop: true,
216
- isHorizontal: false,
217
- lerp: 0.1,
218
- lerpToFixed: false,
219
- };
220
- return mergeWithoutArrays(super._getDefaultProp(), prop);
221
- }
222
- // Set Events
223
- _setEvents() {
224
- // update sizes
225
- this.resize();
226
- this.addViewportCallback('', () => {
227
- this.resize(true);
228
- });
229
- // wheel
230
- this.addEventListeners(this.outer, 'wheel', (e) => {
231
- this._handleWheel(e);
232
- }, {
233
- passive: true,
234
- });
235
- // on scroll
236
- this.addEventListeners(this.outer, 'scroll', () => {
237
- this.outer.scrollTop = 0;
238
- this.outer.scrollLeft = 0;
239
- });
240
- }
241
- _onPropMutate() {
242
- super._onPropMutate();
243
- this.resize();
244
- this._toggle();
245
- }
246
- /**
247
- * Recalculate scroll sizes
248
- */
249
- resize(
250
- /**
251
- * If the method was called natively on window resize
252
- */
253
- native = false) {
254
- // get elements
255
- const { container, outer } = this;
256
- // get sizes
257
- this._clientWidth = outer.clientWidth;
258
- this._clientHeight = outer.clientHeight;
259
- this._scrollWidth = boundVal(container.clientWidth, [this.clientWidth, Infinity]);
260
- this._scrollHeight = boundVal(container.clientHeight, [this.clientHeight, Infinity]);
261
- // force instant change
262
- // it means that after resizing, scrolling will be instantaneous for a while
263
- if (native) {
264
- this._instant = true;
265
- }
266
- // sometimes after resizing it may happen that targets are less or more
267
- // than maximum values of scrolling
268
- // that's why fix it here
269
- if (native) {
270
- this.targetLeft = parseInt(this.targetLeft.toFixed(0), 10);
271
- this.targetTop = parseInt(this.targetTop.toFixed(0), 10);
272
- }
273
- // render elements
274
- this._updateElementsProp();
275
- this.render();
276
- // launch callbacks
277
- this.callbacks.tbt('resize', false);
278
- }
279
- /**
280
- * Recalculate scroll sizes
281
- */
282
- _recalculateSizes() {
283
- const { container } = this;
284
- const height = container.clientHeight;
285
- const width = container.clientWidth;
286
- if ((height !== this.scrollHeight) || (width !== this.scrollHeight)) {
287
- this.resize();
288
- }
289
- }
290
- /**
291
- * Update elements' properties
292
- */
293
- _updateElementsProp() {
294
- for (let index = 0; index < this._elementsLength; index += 1) {
295
- const el = this._elements[index];
296
- // update scroll values
297
- el.customScrollLeft = this.scrollLeft;
298
- el.customScrollTop = this.scrollTop;
299
- // update easing
300
- const easingAttr = el.getAttribute(`${this.prefix}-ease`);
301
- if (easingAttr) {
302
- try {
303
- el.customScrollLerpEase = parseFloat(easingAttr);
304
- }
305
- catch (e) {
306
- //
307
- }
308
- }
309
- }
310
- }
311
- /**
312
- * Event on wheel
313
- */
314
- _handleWheel(evt) {
315
- const { prop } = this;
316
- if (!prop.enabled || prop.useWheel) {
317
- return;
318
- }
319
- // stop propagation if needed
320
- if ((this.targetLeft < 0
321
- || this.targetLeft === this.scrollWidth - this.clientWidth)
322
- || (this.targetTop < 0
323
- || this.targetTop === this.scrollHeight - this.clientHeight)) {
324
- evt.stopPropagation();
325
- }
326
- // get normalized delta
327
- const delta = normalizeWheel(evt);
328
- // set new scroll targets
329
- this.targetLeftDry += prop.isHorizontal ? delta.pixelY : delta.pixelX;
330
- this.targetTopDry += prop.isHorizontal ? delta.pixelX : delta.pixelY;
331
- // play scroll
332
- this.enable();
333
- // launch events
334
- this.callbacks.tbt('wheel', evt);
335
- }
336
- /**
337
- * Toggle animation: Enable / Disable scrolling
338
- */
339
- _toggle() {
340
- if (this.prop.enabled) {
341
- this.enable();
342
- }
343
- else {
344
- this.disable();
345
- }
346
- }
347
- /**
348
- * Enable scrolling
349
- */
350
- enable() {
351
- // set animation callback for the outer AnimationFrame
352
- if (!!this.prop.animationFrame && !this._outerAnimationFrameEvent) {
353
- this._outerAnimationFrameEvent = this.prop.animationFrame.addCallback('frame', this.render.bind(this));
354
- }
355
- else {
356
- // otherwise, check if inner AnimationFrame is created
357
- if (!this._animationFrame) {
358
- this._animationFrame = new AnimationFrame();
359
- this._animationFrame.addCallback('frame', this.render.bind(this));
360
- }
361
- this._animationFrame.play();
362
- }
363
- }
364
- /**
365
- * Disable scrolling
366
- */
367
- disable() {
368
- if (!!this._outerAnimationFrameEvent && !!this.prop.animationFrame) {
369
- this._outerAnimationFrameEvent.remove();
370
- }
371
- if (this._animationFrame) {
372
- this._animationFrame.pause();
373
- }
374
- }
375
- /**
376
- * Render elements
377
- */
378
- render() {
379
- // vars
380
- const { prop } = this;
381
- // recalculate sizes
382
- if (!prop.recalculateSizes) {
383
- this._recalculateSizes();
384
- }
385
- // calculate scroll values
386
- this._scrollLeft = this._lerp(this._scrollLeft, this._targetLeft);
387
- this._scrollTop = this._lerp(this._scrollTop, this._targetTop);
388
- // change elements' values
389
- this._calcElements();
390
- // render
391
- this._renderElements();
392
- // disable instant scrolling
393
- if (this._instant) {
394
- this._instant = false;
395
- }
396
- // launch events
397
- this.callbacks.tbt('render', false);
398
- // stop animation frame if values are approximated
399
- const yDiff = Math.abs(this._targetTop - this._scrollTop);
400
- const xDiff = Math.abs(this._targetLeft - this._scrollLeft);
401
- if (xDiff === 0 && yDiff === 0 && prop.autoStop) {
402
- this.disable();
403
- this.callbacks.tbt('approximate', false);
404
- }
405
- }
406
- /**
407
- * Calculate elements' values.
408
- * @param {boolean} instant - If animation is to be implemented instantly.
409
- */
410
- _calcElements() {
411
- for (let index = 0; index < this._elementsLength; index += 1) {
412
- const el = this._elements[index];
413
- // get element ease
414
- const ease = this._getLerpEase(el);
415
- // change values
416
- if (ease === this.prop.lerp) {
417
- el.customScrollLeft = this._scrollLeft;
418
- el.customScrollTop = this._scrollTop;
419
- }
420
- else {
421
- el.customScrollLeft = this._lerp(el.customScrollLeft, this._targetLeft, ease);
422
- el.customScrollTop = this._lerp(el.customScrollTop, this._targetTop, ease);
423
- }
424
- }
425
- }
426
- /**
427
- * Interpolate values
428
- */
429
- _lerp(current, target, ease = this.prop.lerp) {
430
- const currentEase = this._instant ? 1 : ease;
431
- const val = lerp(current, target, currentEase);
432
- // round the values
433
- if (typeof this.prop.lerpToFixed === 'number') {
434
- const fixed = Math.round(this.prop.lerpToFixed);
435
- return parseFloat(val.toFixed(fixed));
436
- }
437
- return val;
438
- }
439
- /**
440
- * Get element ease
441
- */
442
- _getLerpEase(el) {
443
- if (el) {
444
- return el.customScrollLerpEase || this.prop.lerp;
445
- }
446
- return this.prop.lerp;
447
- }
448
- /**
449
- * Render elements
450
- */
451
- _renderElements() {
452
- for (let index = 0; index < this._elementsLength; index += 1) {
453
- const el = this._elements[index];
454
- // coords
455
- const x = -el.customScrollLeft;
456
- const y = -el.customScrollTop;
457
- // set styles
458
- el.style.transform = `matrix3d(1,0,0.00,0,0.00,1,0.00,0,0,0,1,0, ${x}, ${y}, 0,1)`;
459
- }
460
- }
461
- /**
462
- * Destroy the scroll
463
- */
464
- _destroy() {
465
- super._destroy();
466
- // disable animation
467
- this.disable();
468
- if (this._animationFrame) {
469
- this._animationFrame.destroy();
470
- }
471
- // destroy container
472
- if (!this._containerExists) {
473
- while (this._container.firstChild) {
474
- this._outer.appendChild(this._container.firstChild);
475
- }
476
- this._container.remove();
477
- }
478
- // remove classes
479
- this._outer.classList.remove(this.prefix);
480
- // reset styles
481
- for (let index = 0; index < this._elementsLength; index += 1) {
482
- const el = this._elements[index];
483
- el.style.transform = '';
484
- }
485
- }
486
- }
@@ -1,199 +0,0 @@
1
- import { selectOne } from 'vevet-dom';
2
- import { Component } from '../../base/Component';
3
- import { mergeWithoutArrays } from '../../utils/common';
4
- /**
5
- * The class splits text in an element into words, letters, and lines.
6
- * This may be useful when animating the text.
7
- */
8
- export class SplitText extends Component {
9
- _getDefaultProp() {
10
- const prop = {
11
- container: '.v-text',
12
- resizeTimeout: 0,
13
- append: {
14
- letters: true,
15
- words: true,
16
- lines: false,
17
- },
18
- };
19
- return mergeWithoutArrays(super._getDefaultProp(), prop);
20
- }
21
- // Extra constructor
22
- _constructor() {
23
- this._create();
24
- }
25
- /**
26
- * Text container
27
- */
28
- _container = null;
29
- /**
30
- * Get text container
31
- */
32
- get container() {
33
- return this._container;
34
- }
35
- /**
36
- * innerHTML of the container
37
- */
38
- _html = '';
39
- /**
40
- * textContent of the container
41
- */
42
- _text = '';
43
- /**
44
- * Defines if the text is already split
45
- */
46
- _isSplit = false;
47
- /**
48
- * Text letters
49
- */
50
- _letters = [];
51
- /**
52
- * Get text letters
53
- */
54
- get letters() {
55
- return this._letters;
56
- }
57
- /**
58
- * Create split text
59
- */
60
- _create() {
61
- // get container
62
- const container = selectOne(this.prop.container);
63
- this._container = container;
64
- if (!container) {
65
- return;
66
- }
67
- container.classList.add(`${this.prefix}`);
68
- console.log(this.prefix);
69
- // update variables
70
- this._text = container.textContent;
71
- this._html = container.innerHTML;
72
- console.log(this._container);
73
- }
74
- /**
75
- * Set events
76
- */
77
- _setEvents() {
78
- this.addViewportCallback('', () => {
79
- this._resize();
80
- }, {
81
- timeout: this.prop.resizeTimeout,
82
- name: this.name,
83
- });
84
- }
85
- /**
86
- * Resize the text
87
- */
88
- _resize() {
89
- this.callbacks.tbt('resize', false);
90
- this.split();
91
- }
92
- /**
93
- * Split the text
94
- */
95
- split() {
96
- // break if there's no text
97
- if (!this._text) {
98
- return;
99
- }
100
- // get prop
101
- const { prop } = this;
102
- // split text into letters and words
103
- // this must happen only once
104
- if (!this._isSplit) {
105
- // split
106
- this._splitToWords(this._text);
107
- // this._lettersSplit();
108
- // // clear innerHTML
109
- // this._outer.innerHTML = '';
110
- // // and append
111
- // this._lettersAppend();
112
- // this._wordsAppend();
113
- }
114
- // remove previous lines
115
- // if (this._splitBool) {
116
- // this._linesRemove();
117
- // }
118
- // // append spaces
119
- // if (!prop.appendLines) {
120
- // if (!this._splitBool) {
121
- // this._appendSpaces();
122
- // }
123
- // }
124
- // // split to lines
125
- // if (prop.appendLines) {
126
- // this._appendSpaces();
127
- // this._linesSplit();
128
- // this._removeBr();
129
- // this._linesAppend();
130
- // this._appendSpaces();
131
- // } else {
132
- // this._linesSplit();
133
- // }
134
- // // change value
135
- // this._splitBool = true;
136
- // // remove the class
137
- // this._outer.classList.remove(`${this._prefix}_splitting`);
138
- // // launch callback
139
- // this.lbt('split', this._el);
140
- }
141
- /**
142
- * Split text into words
143
- */
144
- _splitToWords(text) {
145
- console.log(text);
146
- // split text to chars
147
- // const chars = text.split('');
148
- // const el = [];
149
- // let word: string[] = [];
150
- // // gor through all chars and add them to single words
151
- // chars.forEach((char, index) => {
152
- // const charCode = char.charCodeAt(0);
153
- // const isNewLine = charCode === 10;
154
- // const isWhitespace = charCode === 32 || charCode === 160;
155
- // const isLastChar = index === (chars.length - 1);
156
- // // define if a new word
157
- // let isNewWord = false;
158
- // if (isNewLine || isWhitespace || isLastChar) {
159
- // isNewWord = true;
160
- // if (isLastChar) {
161
- // word.push(char);
162
- // }
163
- // }
164
- // // if a new word
165
- // if (isNewWord) {
166
- // // add previous word to elements
167
- // if (word.length > 0) {
168
- // el.push({
169
- // el: false,
170
- // children: word,
171
- // newline: isNewLine,
172
- // content: word.join(''),
173
- // type: 'word',
174
- // });
175
- // }
176
- // word = [];
177
- // } else {
178
- // word.push(char);
179
- // }
180
- // // iteration
181
- // i++;
182
- // });
183
- // // add elements to words
184
- // if (this._prop.appendWords) {
185
- // el.forEach((word) => {
186
- // word.el = dom({
187
- // selector: 'span',
188
- // styles: `${this._prefix}__word`,
189
- // });
190
- // word.el.classList.add();
191
- // if (!this._prop.appendLetters) {
192
- // word.el.innerHTML = word.content;
193
- // }
194
- // });
195
- // }
196
- // // add to stack
197
- // this._el.words = el;
198
- }
199
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Get progress relatively to the scope.
3
- *
4
- * @example
5
- *
6
- * scopeProgress(.35, [0, 1]);
7
- * // => .5
8
- * scopeProgress(.35, [.25, 1]);
9
- * // => .133
10
- */
11
- export default function scopeProgress(
12
- /**
13
- * Current progress
14
- */
15
- progress,
16
- /**
17
- * Progress scope
18
- */
19
- scope) {
20
- const result = (progress - scope[0]) / (scope[1] - scope[0]);
21
- return result;
22
- }