vevet 3.4.0 → 3.5.0

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 (147) hide show
  1. package/lib/cjs/base/Component/index.js.map +1 -1
  2. package/lib/cjs/components/AnimationFrame/index.js.map +1 -1
  3. package/lib/cjs/components/BaseTimeline/index.js.map +1 -1
  4. package/lib/cjs/components/Ctx2DPrerender/index.js.map +1 -1
  5. package/lib/cjs/components/CustomCursor/index.js.map +1 -1
  6. package/lib/cjs/components/DraggerBase/index.js.map +1 -1
  7. package/lib/cjs/components/DraggerDirection/index.js.map +1 -1
  8. package/lib/cjs/components/DraggerMove/index.js.map +1 -1
  9. package/lib/cjs/components/Preloader/index.js.map +1 -1
  10. package/lib/cjs/components/ProgressPreloader/index.js +4 -1
  11. package/lib/cjs/components/ProgressPreloader/index.js.map +1 -1
  12. package/lib/cjs/components/ScrollBar/index.js.map +1 -1
  13. package/lib/cjs/components/ScrollView/index.js.map +1 -1
  14. package/lib/cjs/components/SectionScrollProgress/index.js.map +1 -1
  15. package/lib/cjs/components/SlideProgress/index.js +185 -0
  16. package/lib/cjs/components/SlideProgress/index.js.map +1 -0
  17. package/lib/cjs/components/SlideProgress/types.js +3 -0
  18. package/lib/cjs/components/SlideProgress/types.js.map +1 -0
  19. package/lib/cjs/components/SmoothScroll/index.js.map +1 -1
  20. package/lib/cjs/components/SmoothScrollDragPlugin/index.js.map +1 -1
  21. package/lib/cjs/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
  22. package/lib/cjs/components/SplitText/index.js.map +1 -1
  23. package/lib/cjs/components/Timeline/index.js.map +1 -1
  24. package/lib/cjs/components/index.js +1 -0
  25. package/lib/cjs/components/index.js.map +1 -1
  26. package/lib/cjs/version.js +1 -1
  27. package/lib/esm/base/Component/index.js.map +1 -1
  28. package/lib/esm/components/AnimationFrame/index.js.map +1 -1
  29. package/lib/esm/components/BaseTimeline/index.js.map +1 -1
  30. package/lib/esm/components/Ctx2DPrerender/index.js.map +1 -1
  31. package/lib/esm/components/CustomCursor/index.js.map +1 -1
  32. package/lib/esm/components/DraggerBase/index.js.map +1 -1
  33. package/lib/esm/components/DraggerDirection/index.js.map +1 -1
  34. package/lib/esm/components/DraggerMove/index.js.map +1 -1
  35. package/lib/esm/components/Preloader/index.js.map +1 -1
  36. package/lib/esm/components/ProgressPreloader/index.js +4 -1
  37. package/lib/esm/components/ProgressPreloader/index.js.map +1 -1
  38. package/lib/esm/components/ScrollBar/index.js.map +1 -1
  39. package/lib/esm/components/ScrollView/index.js.map +1 -1
  40. package/lib/esm/components/SectionScrollProgress/index.js.map +1 -1
  41. package/lib/esm/components/SlideProgress/index.js +134 -0
  42. package/lib/esm/components/SlideProgress/index.js.map +1 -0
  43. package/lib/esm/components/SlideProgress/types.js +2 -0
  44. package/lib/esm/components/SlideProgress/types.js.map +1 -0
  45. package/lib/esm/components/SmoothScroll/index.js.map +1 -1
  46. package/lib/esm/components/SmoothScrollDragPlugin/index.js.map +1 -1
  47. package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
  48. package/lib/esm/components/SplitText/index.js.map +1 -1
  49. package/lib/esm/components/Timeline/index.js.map +1 -1
  50. package/lib/esm/components/index.js +1 -0
  51. package/lib/esm/components/index.js.map +1 -1
  52. package/lib/esm/version.js +1 -1
  53. package/lib/types/base/Component/index.d.ts.map +1 -1
  54. package/lib/types/components/AnimationFrame/index.d.ts.map +1 -1
  55. package/lib/types/components/BaseTimeline/index.d.ts.map +1 -1
  56. package/lib/types/components/Ctx2DPrerender/index.d.ts +1 -1
  57. package/lib/types/components/Ctx2DPrerender/index.d.ts.map +1 -1
  58. package/lib/types/components/CustomCursor/index.d.ts.map +1 -1
  59. package/lib/types/components/DraggerBase/index.d.ts.map +1 -1
  60. package/lib/types/components/DraggerDirection/index.d.ts.map +1 -1
  61. package/lib/types/components/DraggerMove/index.d.ts.map +1 -1
  62. package/lib/types/components/Preloader/index.d.ts.map +1 -1
  63. package/lib/types/components/ProgressPreloader/index.d.ts.map +1 -1
  64. package/lib/types/components/ScrollBar/index.d.ts.map +1 -1
  65. package/lib/types/components/ScrollView/index.d.ts.map +1 -1
  66. package/lib/types/components/SectionScrollProgress/index.d.ts.map +1 -1
  67. package/lib/types/components/SlideProgress/index.d.ts +54 -0
  68. package/lib/types/components/SlideProgress/index.d.ts.map +1 -0
  69. package/lib/types/components/SlideProgress/types.d.ts +67 -0
  70. package/lib/types/components/SlideProgress/types.d.ts.map +1 -0
  71. package/lib/types/components/SmoothScroll/index.d.ts.map +1 -1
  72. package/lib/types/components/SmoothScrollDragPlugin/index.d.ts.map +1 -1
  73. package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts.map +1 -1
  74. package/lib/types/components/SplitText/index.d.ts.map +1 -1
  75. package/lib/types/components/Timeline/index.d.ts.map +1 -1
  76. package/lib/types/components/index.d.ts +1 -0
  77. package/lib/types/components/index.d.ts.map +1 -1
  78. package/lib/types/version.d.ts +1 -1
  79. package/package.json +4 -4
  80. package/src/Application/events/PageLoad/index.ts +1 -1
  81. package/src/Application/events/Viewport/index.ts +3 -3
  82. package/src/Application/index.ts +1 -1
  83. package/src/base/Callbacks/index.ts +2 -2
  84. package/src/base/Component/index.ts +4 -2
  85. package/src/base/Module/index.ts +13 -13
  86. package/src/base/Module/stories/index.tsx +1 -1
  87. package/src/base/MutableProps/index.ts +3 -3
  88. package/src/base/MutableProps/stories/index.tsx +1 -1
  89. package/src/base/Plugin/index.ts +2 -2
  90. package/src/components/AnimationFrame/index.ts +8 -5
  91. package/src/components/BaseTimeline/index.ts +6 -4
  92. package/src/components/BaseTimeline/stories/Nested.tsx +1 -1
  93. package/src/components/Ctx2D/index.ts +1 -1
  94. package/src/components/Ctx2DPrerender/index.ts +6 -3
  95. package/src/components/CustomCursor/index.ts +11 -9
  96. package/src/components/DraggerBase/index.ts +10 -8
  97. package/src/components/DraggerDirection/index.ts +6 -3
  98. package/src/components/DraggerMove/index.ts +8 -6
  99. package/src/components/Marquee/index.ts +2 -2
  100. package/src/components/Preloader/index.ts +5 -3
  101. package/src/components/ProgressPreloader/index.ts +16 -10
  102. package/src/components/ProgressPreloader/utils/preloadCustomElement.ts +1 -1
  103. package/src/components/ProgressPreloader/utils/preloadImage.ts +1 -1
  104. package/src/components/ProgressPreloader/utils/preloadVideo.ts +1 -1
  105. package/src/components/ScrollBar/Bar/index.ts +5 -5
  106. package/src/components/ScrollBar/index.ts +6 -4
  107. package/src/components/ScrollBar/stories/Default.tsx +1 -1
  108. package/src/components/ScrollBar/stories/WithInnerScroll.tsx +1 -1
  109. package/src/components/ScrollBar/stories/WithSmoothScrollComponent.tsx +1 -1
  110. package/src/components/ScrollBar/stories/index.stories.tsx +2 -2
  111. package/src/components/ScrollView/index.ts +12 -10
  112. package/src/components/ScrollView/stories/index.tsx +1 -1
  113. package/src/components/SectionScrollProgress/index.ts +6 -3
  114. package/src/components/SectionScrollProgress/stories/index.stories.tsx +1 -1
  115. package/src/components/SlideProgress/index.ts +226 -0
  116. package/src/components/SlideProgress/stories/index.stories.tsx +13 -0
  117. package/src/components/SlideProgress/stories/index.tsx +66 -0
  118. package/src/components/SlideProgress/types.ts +71 -0
  119. package/src/components/SmoothScroll/AnimatonFrame.ts +2 -2
  120. package/src/components/SmoothScroll/Elements.ts +3 -3
  121. package/src/components/SmoothScroll/index.ts +9 -7
  122. package/src/components/SmoothScroll/stories/Default.tsx +1 -1
  123. package/src/components/SmoothScroll/stories/WithHorizontal.tsx +1 -1
  124. package/src/components/SmoothScroll/stories/WithInnerLerp.tsx +1 -1
  125. package/src/components/SmoothScroll/stories/index.stories.tsx +2 -2
  126. package/src/components/SmoothScrollDragPlugin/index.ts +7 -4
  127. package/src/components/SmoothScrollDragPlugin/stories/index.tsx +1 -1
  128. package/src/components/SmoothScrollKeyboardPlugin/index.ts +7 -4
  129. package/src/components/SmoothScrollKeyboardPlugin/stories/index.tsx +1 -1
  130. package/src/components/SplitText/index.ts +5 -3
  131. package/src/components/Timeline/index.ts +4 -3
  132. package/src/components/Timeline/stories/Nested.tsx +1 -1
  133. package/src/components/index.ts +1 -0
  134. package/src/utils/common/mergeWithoutArrays.ts +1 -1
  135. package/src/utils/common/pickObjectProps.ts +1 -1
  136. package/src/utils/common/times.ts +1 -1
  137. package/src/utils/image/load.ts +2 -2
  138. package/src/utils/image/pathsToProps.ts +1 -1
  139. package/src/utils/listeners/onResize.ts +3 -3
  140. package/src/utils/math/clampScope.ts +1 -1
  141. package/src/utils/math/easing.ts +1 -1
  142. package/src/utils/math/lerp.ts +1 -1
  143. package/src/utils/math/normalizeNestedScope.ts +1 -1
  144. package/src/utils/math/wrap.ts +1 -1
  145. package/src/utils/scroll/getScrollValues.ts +1 -1
  146. package/src/utils/scroll/onScroll.ts +7 -7
  147. package/src/version.ts +1 -1
@@ -123,10 +123,10 @@ export default class Bar {
123
123
  const { outer, thumb, props } = this;
124
124
 
125
125
  this._listeners.push(
126
- addEventListener(outer, 'mouseenter', () => this._handleHover(true))
126
+ addEventListener(outer, 'mouseenter', () => this._handleHover(true)),
127
127
  );
128
128
  this._listeners.push(
129
- addEventListener(outer, 'mouseleave', () => this._handleHover(false))
129
+ addEventListener(outer, 'mouseleave', () => this._handleHover(false)),
130
130
  );
131
131
 
132
132
  this._scrollEvent = onScroll({
@@ -189,7 +189,7 @@ export default class Bar {
189
189
 
190
190
  this._actionTimeout = setTimeout(
191
191
  () => this.outer.classList.remove(actionClassName),
192
- 500
192
+ 500,
193
193
  );
194
194
  }
195
195
 
@@ -274,13 +274,13 @@ export default class Bar {
274
274
  if (isHorizontal) {
275
275
  const barSize = clamp(
276
276
  this._outerWidth / (scrollWidth / (scrollWidth - scrollLine)),
277
- [minSize, Infinity]
277
+ [minSize, Infinity],
278
278
  );
279
279
  thumb.style.width = `${barSize}px`;
280
280
  } else {
281
281
  const barSize = clamp(
282
282
  this._outerHeight / (scrollHeight / (scrollHeight - scrollLine)),
283
- [minSize, Infinity]
283
+ [minSize, Infinity],
284
284
  );
285
285
  thumb.style.height = `${barSize}px`;
286
286
  }
@@ -13,8 +13,10 @@ export type { NScrollBar };
13
13
  */
14
14
  export class ScrollBar<
15
15
  StaticProps extends NScrollBar.IStaticProps = NScrollBar.IStaticProps,
16
- ChangeableProps extends NScrollBar.IChangeableProps = NScrollBar.IChangeableProps,
17
- CallbacksTypes extends NScrollBar.ICallbacksTypes = NScrollBar.ICallbacksTypes
16
+ ChangeableProps extends
17
+ NScrollBar.IChangeableProps = NScrollBar.IChangeableProps,
18
+ CallbacksTypes extends
19
+ NScrollBar.ICallbacksTypes = NScrollBar.ICallbacksTypes,
18
20
  > extends ComponentClass<StaticProps, ChangeableProps, CallbacksTypes> {
19
21
  protected _getDefaultProps() {
20
22
  return {
@@ -123,7 +125,7 @@ export class ScrollBar<
123
125
  this.toggleClassName(
124
126
  this.scrollableElement,
125
127
  this.className('-parent'),
126
- true
128
+ true,
127
129
  );
128
130
 
129
131
  // initialize the class
@@ -157,7 +159,7 @@ export class ScrollBar<
157
159
  ? container.addCallback(
158
160
  'resize',
159
161
  () => resizeHandler.debounceResize(),
160
- { name: this.name }
162
+ { name: this.name },
161
163
  )
162
164
  : undefined;
163
165
 
@@ -20,7 +20,7 @@ export const WithDefaultComponent: FC = () => {
20
20
  mollitia illum?
21
21
  </div>
22
22
  ),
23
- 200
23
+ 200,
24
24
  )}
25
25
  </div>
26
26
  );
@@ -37,7 +37,7 @@ export const WithInnerScrollComponent: FC = () => {
37
37
  mollitia illum?
38
38
  </div>
39
39
  ),
40
- 40
40
+ 40,
41
41
  )}
42
42
  </div>
43
43
  );
@@ -41,7 +41,7 @@ export const WithSmoothScrollComponent: FC = () => {
41
41
  mollitia illum?
42
42
  </div>
43
43
  ),
44
- 40
44
+ 40,
45
45
  )}
46
46
  </div>
47
47
  </div>
@@ -15,9 +15,9 @@ export const Default: StoryFn<typeof WithDefaultComponent> = (props) => (
15
15
  );
16
16
 
17
17
  export const WithSmoothScroll: StoryFn<typeof WithSmoothScrollComponent> = (
18
- props
18
+ props,
19
19
  ) => <WithSmoothScrollComponent {...props} />;
20
20
 
21
21
  export const WithInnerScroll: StoryFn<typeof WithInnerScrollComponent> = (
22
- props
22
+ props,
23
23
  ) => <WithInnerScrollComponent {...props} />;
@@ -12,8 +12,10 @@ export type { NScrollView };
12
12
  */
13
13
  export class ScrollView<
14
14
  StaticProps extends NScrollView.IStaticProps = NScrollView.IStaticProps,
15
- ChangeableProps extends NScrollView.IChangeableProps = NScrollView.IChangeableProps,
16
- CallbacksTypes extends NScrollView.ICallbacksTypes = NScrollView.ICallbacksTypes
15
+ ChangeableProps extends
16
+ NScrollView.IChangeableProps = NScrollView.IChangeableProps,
17
+ CallbacksTypes extends
18
+ NScrollView.ICallbacksTypes = NScrollView.ICallbacksTypes,
17
19
  > extends ComponentClass<StaticProps, ChangeableProps, CallbacksTypes> {
18
20
  protected _getDefaultProps() {
19
21
  return {
@@ -148,11 +150,11 @@ export class ScrollView<
148
150
  root: props.intersectionRoot,
149
151
  threshold: 0,
150
152
  rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
151
- }
153
+ },
152
154
  );
153
155
 
154
- this.elements.forEach((element) =>
155
- this._intersectionObserverIn?.observe(element)
156
+ this.elements.forEach(
157
+ (element) => this._intersectionObserverIn?.observe(element),
156
158
  );
157
159
 
158
160
  if (props.states === 'inout') {
@@ -162,11 +164,11 @@ export class ScrollView<
162
164
  root: props.intersectionRoot,
163
165
  threshold: 0,
164
166
  rootMargin: '0px 0px 0px 0px',
165
- }
167
+ },
166
168
  );
167
169
 
168
- this.elements.forEach((element) =>
169
- this._intersectionObserverOut?.observe(element)
170
+ this.elements.forEach(
171
+ (element) => this._intersectionObserverOut?.observe(element),
170
172
  );
171
173
  }
172
174
  }
@@ -219,7 +221,7 @@ export class ScrollView<
219
221
  props.direction === 'horizontal'
220
222
  ? (bounding.left - rootBounding.left) / rootBounding.width
221
223
  : (bounding.top - rootBounding.top) / rootBounding.height,
222
- [0, 1]
224
+ [0, 1],
223
225
  );
224
226
 
225
227
  return progress * props.maxDelay;
@@ -243,7 +245,7 @@ export class ScrollView<
243
245
  protected _handleInOut(
244
246
  elementProp: NScrollView.IElement,
245
247
  isInViewport: boolean,
246
- delay = 0
248
+ delay = 0,
247
249
  ) {
248
250
  const { classToToggle } = this.props;
249
251
  const element = elementProp;
@@ -39,7 +39,7 @@ export const Component: FC = () => {
39
39
  {index} Lorem ipsum dolor sit amet consectetur adipisicing elit.
40
40
  </div>
41
41
  ),
42
- 200
42
+ 200,
43
43
  )}
44
44
  </div>
45
45
  );
@@ -12,9 +12,12 @@ export type { NScrollSectionProgress };
12
12
  * Trace scroll progress of a section
13
13
  */
14
14
  export class SectionScrollProgress<
15
- StaticProps extends NScrollSectionProgress.IStaticProps = NScrollSectionProgress.IStaticProps,
16
- ChangeableProps extends NScrollSectionProgress.IChangeableProps = NScrollSectionProgress.IChangeableProps,
17
- CallbacksTypes extends NScrollSectionProgress.ICallbacksTypes = NScrollSectionProgress.ICallbacksTypes
15
+ StaticProps extends
16
+ NScrollSectionProgress.IStaticProps = NScrollSectionProgress.IStaticProps,
17
+ ChangeableProps extends
18
+ NScrollSectionProgress.IChangeableProps = NScrollSectionProgress.IChangeableProps,
19
+ CallbacksTypes extends
20
+ NScrollSectionProgress.ICallbacksTypes = NScrollSectionProgress.ICallbacksTypes,
18
21
  > extends ComponentClass<StaticProps, ChangeableProps, CallbacksTypes> {
19
22
  protected _getDefaultProps() {
20
23
  return {
@@ -14,5 +14,5 @@ export const Default: StoryFn<typeof DefalultComponent> = (props) => (
14
14
  );
15
15
 
16
16
  export const WithCustomScroll: StoryFn<typeof WithCustomScrollComponent> = (
17
- props
17
+ props,
18
18
  ) => <WithCustomScrollComponent {...props} />;
@@ -0,0 +1,226 @@
1
+ import { Component as ComponentClass } from '@/base/Component';
2
+ import { NSlideProgress } from './types';
3
+ import { clamp, lerp } from '@/utils/math';
4
+ import { normalizeWheel } from '@/utils/scroll/normalizeWheel';
5
+ import { AnimationFrame } from '../AnimationFrame';
6
+ import { DraggerMove, NDraggerMove } from '../DraggerMove';
7
+ import { Timeline } from '../Timeline';
8
+
9
+ export type { NSlideProgress };
10
+
11
+ /**
12
+ * Slide progress handler
13
+ */
14
+ export class SlideProgress<
15
+ StaticProps extends NSlideProgress.IStaticProps = NSlideProgress.IStaticProps,
16
+ ChangeableProps extends
17
+ NSlideProgress.IChangeableProps = NSlideProgress.IChangeableProps,
18
+ CallbacksTypes extends
19
+ NSlideProgress.ICallbacksTypes = NSlideProgress.ICallbacksTypes,
20
+ > extends ComponentClass<StaticProps, ChangeableProps, CallbacksTypes> {
21
+ protected _getDefaultProps() {
22
+ return {
23
+ ...super._getDefaultProps(),
24
+ min: 0,
25
+ max: 3,
26
+ step: 1,
27
+ ease: 0.1,
28
+ friction: 0.5,
29
+ hasDrag: true,
30
+ dragSpeed: 1,
31
+ dragDirection: 'y',
32
+ hasWheel: true,
33
+ wheelSpeed: 1,
34
+ };
35
+ }
36
+
37
+ /** Animation frame */
38
+ protected _animationFrame: AnimationFrame;
39
+
40
+ /** Dragger events */
41
+ protected _dragger: DraggerMove;
42
+
43
+ /** Progress (current and target) */
44
+ protected _progressLerp: NSlideProgress.IWithLerp = { current: 0, target: 0 };
45
+
46
+ /** Progress */
47
+ get progress() {
48
+ return this._progressLerp.current;
49
+ }
50
+
51
+ /** Stepped progress */
52
+ get steppedProgress() {
53
+ return this._getNearestStep(this._progressLerp.current);
54
+ }
55
+
56
+ /** Progress timeline */
57
+ protected _timelineTo?: Timeline;
58
+
59
+ constructor(initialProps?: StaticProps & ChangeableProps, canInit = true) {
60
+ super(initialProps, false);
61
+
62
+ const { container } = this.props;
63
+
64
+ // create animation frame
65
+ this._animationFrame = new AnimationFrame();
66
+ this._animationFrame.addCallback('frame', () =>
67
+ this._handleAnimationFrame(),
68
+ );
69
+
70
+ // create dragger
71
+ this._dragger = new DraggerMove({ container });
72
+ this._dragger.addCallback('move', (event) => this._handleDrag(event));
73
+ this._dragger.addCallback('start', (event) =>
74
+ event.event.stopPropagation(),
75
+ );
76
+
77
+ // add wheel event
78
+ this.addEventListener(container, 'wheel', (event) =>
79
+ this._handleWheel(event),
80
+ );
81
+
82
+ // initialize the class
83
+ if (canInit) {
84
+ this.init();
85
+ }
86
+ }
87
+
88
+ protected _onPropsMutate() {
89
+ super._onPropsMutate();
90
+
91
+ this._dragger.changeProps({ isEnabled: this.props.hasDrag });
92
+ }
93
+
94
+ /** Handle wheel event */
95
+ protected _handleWheel(event: WheelEvent) {
96
+ if (this._timelineTo || !this.props.hasWheel) {
97
+ return;
98
+ }
99
+
100
+ const { _progressLerp: progress } = this;
101
+ const { container, min, max, wheelSpeed } = this.props;
102
+
103
+ const wheel = normalizeWheel(event);
104
+ const y = (wheel.pixelY / container.clientHeight) * wheelSpeed;
105
+
106
+ progress.target = clamp(progress.target + y, [min, max]);
107
+
108
+ this._animationFrame.play();
109
+ }
110
+
111
+ /** Handler drag move event */
112
+ protected _handleDrag({ step }: NDraggerMove.IMoveParameter) {
113
+ if (this._timelineTo) {
114
+ return;
115
+ }
116
+
117
+ const { _progressLerp: progress } = this;
118
+ const { container, dragSpeed, hasDrag, dragDirection, min, max } =
119
+ this.props;
120
+
121
+ if (!hasDrag) {
122
+ return;
123
+ }
124
+
125
+ const defaultIterator = dragDirection === 'y' ? step.y : step.x;
126
+ const iterator = (defaultIterator * dragSpeed) / container.clientHeight;
127
+
128
+ progress.target = clamp(progress.target - iterator, [min, max]);
129
+
130
+ this._animationFrame.play();
131
+ }
132
+
133
+ /** Get nearest stepped value to given progress */
134
+ protected _getNearestStep(value: number) {
135
+ return Math.round(value / this.props.step) * this.props.step;
136
+ }
137
+
138
+ /** Callback on animation frame */
139
+ protected _handleAnimationFrame() {
140
+ const { _progressLerp: progress } = this;
141
+ const { ease, friction, step } = this.props;
142
+ const { easeMultiplier } = this._animationFrame;
143
+
144
+ const nearestSteppedProgress = this._getNearestStep(progress.target);
145
+
146
+ if (!this._timelineTo) {
147
+ progress.target = lerp(
148
+ progress.target,
149
+ nearestSteppedProgress,
150
+ friction * ease * easeMultiplier,
151
+ );
152
+
153
+ this._updateCurrentProgress(ease * easeMultiplier);
154
+
155
+ if (
156
+ progress.current === progress.target &&
157
+ progress.current % step === 0
158
+ ) {
159
+ this._animationFrame.pause();
160
+ }
161
+ }
162
+
163
+ this.render();
164
+ }
165
+
166
+ /** Render scene */
167
+ public render() {
168
+ this.callbacks.tbt('render', undefined);
169
+ }
170
+
171
+ /** Interpolate current progress & launch callbacks if needed */
172
+ protected _updateCurrentProgress(ease: number) {
173
+ const progress = this._progressLerp;
174
+
175
+ const prevSteppedProgress = this._getNearestStep(progress.current);
176
+
177
+ progress.current = lerp(progress.current, progress.target, ease);
178
+
179
+ const nextSteppedProgress = this._getNearestStep(progress.current);
180
+
181
+ if (prevSteppedProgress !== nextSteppedProgress) {
182
+ this.callbacks.tbt('step', undefined);
183
+ }
184
+ }
185
+
186
+ /** Animate progress to a certain value */
187
+ public to({
188
+ value,
189
+ duration = 500,
190
+ onProgress,
191
+ onEnd,
192
+ }: NSlideProgress.IToProps) {
193
+ const startValue = this._progressLerp.current;
194
+
195
+ const timeline = new Timeline({ duration });
196
+ this._timelineTo = timeline;
197
+
198
+ timeline.addCallback('progress', (data) => {
199
+ this._progressLerp.target = lerp(startValue, value, data.easing);
200
+ this._updateCurrentProgress(1);
201
+
202
+ onProgress?.(data);
203
+ });
204
+
205
+ timeline.addCallback('end', () => {
206
+ this._timelineTo?.destroy();
207
+ this._timelineTo = undefined;
208
+
209
+ onEnd?.();
210
+ });
211
+
212
+ timeline.play();
213
+
214
+ this._animationFrame.play();
215
+ }
216
+
217
+ /** Destroy the module */
218
+ protected _destroy() {
219
+ super._destroy();
220
+
221
+ this._animationFrame.destroy();
222
+ this._dragger.destroy();
223
+
224
+ this._timelineTo?.destroy();
225
+ }
226
+ }
@@ -0,0 +1,13 @@
1
+ import type { StoryObj, Meta } from '@storybook/react';
2
+ import { Component } from '.';
3
+
4
+ type TComponent = typeof Component;
5
+
6
+ const meta: Meta<TComponent> = {
7
+ title: 'Components/SlideProgress',
8
+ component: Component,
9
+ };
10
+
11
+ export default meta;
12
+
13
+ export const Default: StoryObj<TComponent> = {};
@@ -0,0 +1,66 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import React, { FC, useEffect, useRef } from 'react';
3
+ import { SlideProgress } from '..';
4
+
5
+ export const Component: FC = () => {
6
+ const containerRef = useRef<HTMLDivElement>(null);
7
+
8
+ const colors = ['#A8E6CF', '#DCEDC1', '#FFD3B6', '#FFAAA5', '#FF8B94'];
9
+ const { length } = colors;
10
+
11
+ useEffect(() => {
12
+ if (!containerRef.current) {
13
+ return undefined;
14
+ }
15
+
16
+ const instance = new SlideProgress({
17
+ container: containerRef.current,
18
+ min: 0,
19
+ max: length - 1,
20
+ step: 0.5,
21
+ });
22
+
23
+ const elements = Array.from(containerRef.current.children) as HTMLElement[];
24
+
25
+ instance.addCallback('render', () => {
26
+ elements.forEach((element, index) => {
27
+ const y = instance.progress * -100 + index * 100;
28
+ element.style.transform = `translate(0, ${y}%)`;
29
+ });
30
+ });
31
+
32
+ instance.render();
33
+
34
+ return () => instance.destroy();
35
+ }, [length]);
36
+
37
+ return (
38
+ <>
39
+ <p>Scroll the block below</p>
40
+
41
+ <div
42
+ ref={containerRef}
43
+ style={{
44
+ position: 'relative',
45
+ width: 300,
46
+ height: 300,
47
+ overflow: 'hidden',
48
+ }}
49
+ >
50
+ {colors.map((color) => (
51
+ <div
52
+ key={color}
53
+ style={{
54
+ position: 'absolute',
55
+ top: '0',
56
+ left: '0',
57
+ width: '100%',
58
+ height: '100%',
59
+ backgroundColor: color,
60
+ }}
61
+ />
62
+ ))}
63
+ </div>
64
+ </>
65
+ );
66
+ };
@@ -0,0 +1,71 @@
1
+ import { NComponent } from '@/base/Component/types';
2
+ import { NTimeline } from '../Timeline';
3
+
4
+ export namespace NSlideProgress {
5
+ export interface IStaticProps extends NComponent.IStaticProps {
6
+ /** HTML Container */
7
+ container: HTMLElement;
8
+ }
9
+
10
+ export interface IChangeableProps extends NComponent.IChangeableProps {
11
+ /** Minimum progress value */
12
+ min: number;
13
+ /** Maximum progress value */
14
+ max: number;
15
+ /** Progress step */
16
+ step: number;
17
+ /**
18
+ * Linear interpolation ease
19
+ * @default 0.1
20
+ */
21
+ ease?: number;
22
+ /**
23
+ * Linear interpolation friction
24
+ * @default 0.5
25
+ */
26
+ friction?: number;
27
+ /**
28
+ * Use drag events
29
+ * @default true
30
+ */
31
+ hasDrag?: boolean;
32
+ /**
33
+ * Dragger speed
34
+ * @default 1
35
+ */
36
+ dragSpeed?: number;
37
+ /**
38
+ * Dragger direction
39
+ * @default 'y'
40
+ */
41
+ dragDirection?: 'x' | 'y';
42
+ /**
43
+ * Use wheel events
44
+ * @default true
45
+ */
46
+ hasWheel?: boolean;
47
+ /**
48
+ * Wheel speed
49
+ * @default 1
50
+ */
51
+ wheelSpeed?: number;
52
+ }
53
+
54
+ export interface ICallbacksTypes extends NComponent.ICallbacksTypes {
55
+ render: undefined;
56
+ step: undefined;
57
+ }
58
+
59
+ export interface IWithLerp {
60
+ current: number;
61
+ target: number;
62
+ }
63
+
64
+ export interface IToProps {
65
+ value: number;
66
+ /** @default 500 */
67
+ duration?: number;
68
+ onProgress?: (props: NTimeline.ICallbacksTypes['progress']) => void;
69
+ onEnd?: () => void;
70
+ }
71
+ }
@@ -32,7 +32,7 @@ export class AnimationFrame {
32
32
  this._animationFrameEvent = this.props.outerAnimationFrame.addCallback(
33
33
  'frame',
34
34
  () => this.props.callback(),
35
- { name: 'SmoothScroll' }
35
+ { name: 'SmoothScroll' },
36
36
  );
37
37
  }
38
38
 
@@ -43,7 +43,7 @@ export class AnimationFrame {
43
43
  if (!this._innerAnimationFrame) {
44
44
  this._innerAnimationFrame = new AnimationFrameClass({ fps: 'auto' });
45
45
  this._innerAnimationFrame.addCallback('frame', () =>
46
- this.props.callback()
46
+ this.props.callback(),
47
47
  );
48
48
  }
49
49
 
@@ -61,8 +61,8 @@ export class Elements {
61
61
  this._elements = Array.from(
62
62
  selectAll(
63
63
  this.props.elements,
64
- this.props.container
65
- ) as NodeListOf<NSmoothScroll.IElement>
64
+ this.props.container,
65
+ ) as NodeListOf<NSmoothScroll.IElement>,
66
66
  );
67
67
  } else {
68
68
  this._elements = [this._wrapper as NSmoothScroll.IElement];
@@ -123,7 +123,7 @@ export class Elements {
123
123
  return array.every(
124
124
  ({ smoothScrollLeft, smoothScrollTop }) =>
125
125
  smoothScrollLeft === array[0].smoothScrollLeft &&
126
- smoothScrollTop === array[0].smoothScrollTop
126
+ smoothScrollTop === array[0].smoothScrollTop,
127
127
  );
128
128
  }
129
129
 
@@ -15,8 +15,10 @@ export type { NSmoothScroll };
15
15
  */
16
16
  export class SmoothScroll<
17
17
  StaticProps extends NSmoothScroll.IStaticProps = NSmoothScroll.IStaticProps,
18
- ChangeableProps extends NSmoothScroll.IChangeableProps = NSmoothScroll.IChangeableProps,
19
- CallbacksTypes extends NSmoothScroll.ICallbacksTypes = NSmoothScroll.ICallbacksTypes
18
+ ChangeableProps extends
19
+ NSmoothScroll.IChangeableProps = NSmoothScroll.IChangeableProps,
20
+ CallbacksTypes extends
21
+ NSmoothScroll.ICallbacksTypes = NSmoothScroll.ICallbacksTypes,
20
22
  >
21
23
  extends ComponentClass<StaticProps, ChangeableProps, CallbacksTypes>
22
24
  implements IScrollLike
@@ -288,7 +290,7 @@ export class SmoothScroll<
288
290
 
289
291
  // wheel
290
292
  this.addEventListener(this.container, 'wheel', (event) =>
291
- this.handleWheel(event)
293
+ this.handleWheel(event),
292
294
  );
293
295
 
294
296
  // prevent native scroll
@@ -324,7 +326,7 @@ export class SmoothScroll<
324
326
  this._recalculateScrollSizes();
325
327
  }
326
328
  }) as any,
327
- { isProtected: true, name: this.name }
329
+ { isProtected: true, name: this.name },
328
330
  );
329
331
  }
330
332
  }
@@ -365,7 +367,7 @@ export class SmoothScroll<
365
367
  /** Resize the scene */
366
368
  protected _resize(
367
369
  /** If the method was called natively on window resize */
368
- isNative = false
370
+ isNative = false,
369
371
  ) {
370
372
  const { container, wrapper } = this;
371
373
 
@@ -507,13 +509,13 @@ export class SmoothScroll<
507
509
  element.smoothScrollLeft = this._lerp(
508
510
  element.smoothScrollLeft,
509
511
  this._targetLeft,
510
- elementLerp
512
+ elementLerp,
511
513
  );
512
514
 
513
515
  element.smoothScrollTop = this._lerp(
514
516
  element.smoothScrollTop,
515
517
  this._targetTop,
516
- elementLerp
518
+ elementLerp,
517
519
  );
518
520
  }
519
521
  }
@@ -55,7 +55,7 @@ export const DefaultComponent: FC = () => {
55
55
  dolores placeat mollitia illum?
56
56
  </div>
57
57
  ),
58
- 40
58
+ 40,
59
59
  )}
60
60
  </div>
61
61
  </div>