vevet 3.3.2 → 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 (167) 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/Ctx2D/index.js.map +1 -1
  5. package/lib/cjs/components/Ctx2DPrerender/index.js.map +1 -1
  6. package/lib/cjs/components/CustomCursor/index.js.map +1 -1
  7. package/lib/cjs/components/DraggerBase/index.js.map +1 -1
  8. package/lib/cjs/components/DraggerDirection/index.js.map +1 -1
  9. package/lib/cjs/components/DraggerMove/index.js.map +1 -1
  10. package/lib/cjs/components/Preloader/index.js.map +1 -1
  11. package/lib/cjs/components/ProgressPreloader/index.js +4 -1
  12. package/lib/cjs/components/ProgressPreloader/index.js.map +1 -1
  13. package/lib/cjs/components/ScrollBar/index.js.map +1 -1
  14. package/lib/cjs/components/ScrollView/index.js.map +1 -1
  15. package/lib/cjs/components/SectionScrollProgress/index.js.map +1 -1
  16. package/lib/cjs/components/SlideProgress/index.js +185 -0
  17. package/lib/cjs/components/SlideProgress/index.js.map +1 -0
  18. package/lib/cjs/components/SlideProgress/types.js +3 -0
  19. package/lib/cjs/components/SlideProgress/types.js.map +1 -0
  20. package/lib/cjs/components/SmoothScroll/index.js.map +1 -1
  21. package/lib/cjs/components/SmoothScrollDragPlugin/index.js.map +1 -1
  22. package/lib/cjs/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
  23. package/lib/cjs/components/SplitText/index.js.map +1 -1
  24. package/lib/cjs/components/Timeline/index.js.map +1 -1
  25. package/lib/cjs/components/index.js +1 -0
  26. package/lib/cjs/components/index.js.map +1 -1
  27. package/lib/cjs/version.js +1 -1
  28. package/lib/esm/base/Component/index.js.map +1 -1
  29. package/lib/esm/components/AnimationFrame/index.js.map +1 -1
  30. package/lib/esm/components/BaseTimeline/index.js.map +1 -1
  31. package/lib/esm/components/Ctx2D/index.js.map +1 -1
  32. package/lib/esm/components/Ctx2DPrerender/index.js.map +1 -1
  33. package/lib/esm/components/CustomCursor/index.js.map +1 -1
  34. package/lib/esm/components/DraggerBase/index.js.map +1 -1
  35. package/lib/esm/components/DraggerDirection/index.js.map +1 -1
  36. package/lib/esm/components/DraggerMove/index.js.map +1 -1
  37. package/lib/esm/components/Preloader/index.js.map +1 -1
  38. package/lib/esm/components/ProgressPreloader/index.js +4 -1
  39. package/lib/esm/components/ProgressPreloader/index.js.map +1 -1
  40. package/lib/esm/components/ScrollBar/index.js.map +1 -1
  41. package/lib/esm/components/ScrollView/index.js.map +1 -1
  42. package/lib/esm/components/SectionScrollProgress/index.js.map +1 -1
  43. package/lib/esm/components/SlideProgress/index.js +134 -0
  44. package/lib/esm/components/SlideProgress/index.js.map +1 -0
  45. package/lib/esm/components/SlideProgress/types.js +2 -0
  46. package/lib/esm/components/SlideProgress/types.js.map +1 -0
  47. package/lib/esm/components/SmoothScroll/index.js.map +1 -1
  48. package/lib/esm/components/SmoothScrollDragPlugin/index.js.map +1 -1
  49. package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
  50. package/lib/esm/components/SplitText/index.js.map +1 -1
  51. package/lib/esm/components/Timeline/index.js.map +1 -1
  52. package/lib/esm/components/index.js +1 -0
  53. package/lib/esm/components/index.js.map +1 -1
  54. package/lib/esm/version.js +1 -1
  55. package/lib/types/base/Component/index.d.ts.map +1 -1
  56. package/lib/types/components/AnimationFrame/index.d.ts +11 -11
  57. package/lib/types/components/AnimationFrame/index.d.ts.map +1 -1
  58. package/lib/types/components/BaseTimeline/index.d.ts +7 -4
  59. package/lib/types/components/BaseTimeline/index.d.ts.map +1 -1
  60. package/lib/types/components/Ctx2D/index.d.ts +6 -6
  61. package/lib/types/components/Ctx2D/index.d.ts.map +1 -1
  62. package/lib/types/components/Ctx2DPrerender/index.d.ts +1 -1
  63. package/lib/types/components/Ctx2DPrerender/index.d.ts.map +1 -1
  64. package/lib/types/components/CustomCursor/index.d.ts +20 -19
  65. package/lib/types/components/CustomCursor/index.d.ts.map +1 -1
  66. package/lib/types/components/DraggerBase/index.d.ts +11 -10
  67. package/lib/types/components/DraggerBase/index.d.ts.map +1 -1
  68. package/lib/types/components/DraggerDirection/index.d.ts.map +1 -1
  69. package/lib/types/components/DraggerMove/index.d.ts +1 -1
  70. package/lib/types/components/DraggerMove/index.d.ts.map +1 -1
  71. package/lib/types/components/Marquee/index.d.ts +2 -1
  72. package/lib/types/components/Marquee/index.d.ts.map +1 -1
  73. package/lib/types/components/Preloader/index.d.ts +7 -7
  74. package/lib/types/components/Preloader/index.d.ts.map +1 -1
  75. package/lib/types/components/ProgressPreloader/index.d.ts +11 -9
  76. package/lib/types/components/ProgressPreloader/index.d.ts.map +1 -1
  77. package/lib/types/components/ScrollBar/index.d.ts +5 -4
  78. package/lib/types/components/ScrollBar/index.d.ts.map +1 -1
  79. package/lib/types/components/ScrollView/index.d.ts +1 -1
  80. package/lib/types/components/ScrollView/index.d.ts.map +1 -1
  81. package/lib/types/components/SectionScrollProgress/index.d.ts.map +1 -1
  82. package/lib/types/components/SlideProgress/index.d.ts +54 -0
  83. package/lib/types/components/SlideProgress/index.d.ts.map +1 -0
  84. package/lib/types/components/SlideProgress/types.d.ts +67 -0
  85. package/lib/types/components/SlideProgress/types.d.ts.map +1 -0
  86. package/lib/types/components/SmoothScroll/index.d.ts +6 -4
  87. package/lib/types/components/SmoothScroll/index.d.ts.map +1 -1
  88. package/lib/types/components/SmoothScrollDragPlugin/index.d.ts +12 -10
  89. package/lib/types/components/SmoothScrollDragPlugin/index.d.ts.map +1 -1
  90. package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts +5 -4
  91. package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts.map +1 -1
  92. package/lib/types/components/SplitText/index.d.ts +13 -13
  93. package/lib/types/components/SplitText/index.d.ts.map +1 -1
  94. package/lib/types/components/Timeline/index.d.ts +5 -5
  95. package/lib/types/components/Timeline/index.d.ts.map +1 -1
  96. package/lib/types/components/index.d.ts +1 -0
  97. package/lib/types/components/index.d.ts.map +1 -1
  98. package/lib/types/version.d.ts +1 -1
  99. package/package.json +4 -4
  100. package/src/Application/events/PageLoad/index.ts +1 -1
  101. package/src/Application/events/Viewport/index.ts +3 -3
  102. package/src/Application/index.ts +1 -1
  103. package/src/base/Callbacks/index.ts +2 -2
  104. package/src/base/Component/index.ts +4 -2
  105. package/src/base/Module/index.ts +13 -13
  106. package/src/base/Module/stories/index.tsx +1 -1
  107. package/src/base/MutableProps/index.ts +3 -3
  108. package/src/base/MutableProps/stories/index.tsx +1 -1
  109. package/src/base/Plugin/index.ts +2 -2
  110. package/src/components/AnimationFrame/index.ts +19 -16
  111. package/src/components/BaseTimeline/index.ts +10 -8
  112. package/src/components/BaseTimeline/stories/Nested.tsx +1 -1
  113. package/src/components/Ctx2D/index.ts +7 -7
  114. package/src/components/Ctx2DPrerender/index.ts +6 -3
  115. package/src/components/CustomCursor/index.ts +30 -28
  116. package/src/components/DraggerBase/index.ts +20 -18
  117. package/src/components/DraggerDirection/index.ts +6 -3
  118. package/src/components/DraggerMove/index.ts +9 -7
  119. package/src/components/Marquee/index.ts +3 -3
  120. package/src/components/Preloader/index.ts +12 -10
  121. package/src/components/ProgressPreloader/index.ts +25 -19
  122. package/src/components/ProgressPreloader/utils/preloadCustomElement.ts +1 -1
  123. package/src/components/ProgressPreloader/utils/preloadImage.ts +1 -1
  124. package/src/components/ProgressPreloader/utils/preloadVideo.ts +1 -1
  125. package/src/components/ScrollBar/Bar/index.ts +5 -5
  126. package/src/components/ScrollBar/index.ts +10 -8
  127. package/src/components/ScrollBar/stories/Default.tsx +1 -1
  128. package/src/components/ScrollBar/stories/WithInnerScroll.tsx +1 -1
  129. package/src/components/ScrollBar/stories/WithSmoothScrollComponent.tsx +1 -1
  130. package/src/components/ScrollBar/stories/index.stories.tsx +2 -2
  131. package/src/components/ScrollView/index.ts +13 -11
  132. package/src/components/ScrollView/stories/index.tsx +1 -1
  133. package/src/components/SectionScrollProgress/index.ts +6 -3
  134. package/src/components/SectionScrollProgress/stories/index.stories.tsx +1 -1
  135. package/src/components/SlideProgress/index.ts +226 -0
  136. package/src/components/SlideProgress/stories/index.stories.tsx +13 -0
  137. package/src/components/SlideProgress/stories/index.tsx +66 -0
  138. package/src/components/SlideProgress/types.ts +71 -0
  139. package/src/components/SmoothScroll/AnimatonFrame.ts +2 -2
  140. package/src/components/SmoothScroll/Elements.ts +3 -3
  141. package/src/components/SmoothScroll/index.ts +13 -11
  142. package/src/components/SmoothScroll/stories/Default.tsx +1 -1
  143. package/src/components/SmoothScroll/stories/WithHorizontal.tsx +1 -1
  144. package/src/components/SmoothScroll/stories/WithInnerLerp.tsx +1 -1
  145. package/src/components/SmoothScroll/stories/index.stories.tsx +2 -2
  146. package/src/components/SmoothScrollDragPlugin/index.ts +17 -14
  147. package/src/components/SmoothScrollDragPlugin/stories/index.tsx +1 -1
  148. package/src/components/SmoothScrollKeyboardPlugin/index.ts +11 -8
  149. package/src/components/SmoothScrollKeyboardPlugin/stories/index.tsx +1 -1
  150. package/src/components/SplitText/index.ts +18 -16
  151. package/src/components/Timeline/index.ts +9 -8
  152. package/src/components/Timeline/stories/Nested.tsx +1 -1
  153. package/src/components/index.ts +1 -0
  154. package/src/utils/common/mergeWithoutArrays.ts +1 -1
  155. package/src/utils/common/pickObjectProps.ts +1 -1
  156. package/src/utils/common/times.ts +1 -1
  157. package/src/utils/image/load.ts +2 -2
  158. package/src/utils/image/pathsToProps.ts +1 -1
  159. package/src/utils/listeners/onResize.ts +3 -3
  160. package/src/utils/math/clampScope.ts +1 -1
  161. package/src/utils/math/easing.ts +1 -1
  162. package/src/utils/math/lerp.ts +1 -1
  163. package/src/utils/math/normalizeNestedScope.ts +1 -1
  164. package/src/utils/math/wrap.ts +1 -1
  165. package/src/utils/scroll/getScrollValues.ts +1 -1
  166. package/src/utils/scroll/onScroll.ts +7 -7
  167. package/src/version.ts +1 -1
@@ -15,9 +15,12 @@ export type { NProgressPreloader };
15
15
  * Page preloader with smooth progress calculation
16
16
  */
17
17
  export class ProgressPreloader<
18
- StaticProps extends NProgressPreloader.IStaticProps = NProgressPreloader.IStaticProps,
19
- ChangeableProps extends NProgressPreloader.IChangeableProps = NProgressPreloader.IChangeableProps,
20
- CallbacksTypes extends NProgressPreloader.ICallbacksTypes = NProgressPreloader.ICallbacksTypes
18
+ StaticProps extends
19
+ NProgressPreloader.IStaticProps = NProgressPreloader.IStaticProps,
20
+ ChangeableProps extends
21
+ NProgressPreloader.IChangeableProps = NProgressPreloader.IChangeableProps,
22
+ CallbacksTypes extends
23
+ NProgressPreloader.ICallbacksTypes = NProgressPreloader.ICallbacksTypes,
21
24
  > extends Preloader<StaticProps, ChangeableProps, CallbacksTypes> {
22
25
  protected _getDefaultProps() {
23
26
  return {
@@ -33,7 +36,7 @@ export class ProgressPreloader<
33
36
  }
34
37
 
35
38
  /** Images to be preloaded */
36
- private _images: HTMLImageElement[];
39
+ protected _images: HTMLImageElement[];
37
40
 
38
41
  /** Images to be preloaded */
39
42
  get images() {
@@ -41,7 +44,7 @@ export class ProgressPreloader<
41
44
  }
42
45
 
43
46
  /** Videos to be preloaded */
44
- private _videos: HTMLVideoElement[];
47
+ protected _videos: HTMLVideoElement[];
45
48
 
46
49
  /** Videos to be preloaded */
47
50
  get videos() {
@@ -49,14 +52,14 @@ export class ProgressPreloader<
49
52
  }
50
53
 
51
54
  /** Custom resources to be preloaded */
52
- private _customResources: NProgressPreloader.ICustomResourceData[];
55
+ protected _customResources: NProgressPreloader.ICustomResourceData[];
53
56
 
54
57
  /** Custom resources to be preloaded */
55
58
  get customResources() {
56
59
  return this._customResources;
57
60
  }
58
61
 
59
- private _resourcesQuantity: number;
62
+ protected _resourcesQuantity: number;
60
63
 
61
64
  /** Quantity of resources to be preloader */
62
65
  get resourcesQuantity() {
@@ -71,7 +74,7 @@ export class ProgressPreloader<
71
74
  }
72
75
 
73
76
  /** Quantity of loaded resources */
74
- private _loadedResourcesQuantity: number;
77
+ protected _loadedResourcesQuantity: number;
75
78
 
76
79
  /** Quantity of loaded resources */
77
80
  get loadedResourcesQuantity() {
@@ -84,7 +87,7 @@ export class ProgressPreloader<
84
87
  }
85
88
 
86
89
  /** Preloader progress */
87
- private _progress: number;
90
+ protected _progress: number;
88
91
 
89
92
  /** Preloader progress */
90
93
  get progress() {
@@ -98,10 +101,10 @@ export class ProgressPreloader<
98
101
  }
99
102
 
100
103
  /** Animation frame for smooth progress calculation */
101
- private _animationFrame?: AnimationFrame;
104
+ protected _animationFrame?: AnimationFrame;
102
105
 
103
106
  /** Timeline to finish progress animation */
104
- private _endTimeline?: Timeline;
107
+ protected _endTimeline?: Timeline;
105
108
 
106
109
  constructor(initialProps?: StaticProps & ChangeableProps, canInit = true) {
107
110
  super(initialProps, false);
@@ -190,7 +193,7 @@ export class ProgressPreloader<
190
193
 
191
194
  let loadCount = parseInt(
192
195
  element.getAttribute('data-load-count') || '1',
193
- 10
196
+ 10,
194
197
  );
195
198
 
196
199
  loadCount = Number.isNaN(loadCount)
@@ -224,7 +227,7 @@ export class ProgressPreloader<
224
227
  resolve();
225
228
  }
226
229
  },
227
- { isProtected: true, name: this.name }
230
+ { isProtected: true, name: this.name },
228
231
  );
229
232
  });
230
233
  }
@@ -233,29 +236,32 @@ export class ProgressPreloader<
233
236
  protected _preloadResources() {
234
237
  this.images.forEach((image) =>
235
238
  preloadImage(image, (isSuccess) =>
236
- this._handleLoadedResource({ element: image, isSuccess })
237
- )
239
+ this._handleLoadedResource({ element: image, isSuccess }),
240
+ ),
238
241
  );
239
242
 
240
243
  // preload videos
241
244
  this.videos.forEach((video) =>
242
245
  preloadVideo(video, (isSuccess) =>
243
- this._handleLoadedResource({ element: video, isSuccess })
244
- )
246
+ this._handleLoadedResource({ element: video, isSuccess }),
247
+ ),
245
248
  );
246
249
 
247
250
  // preload custom resources
248
251
  this._customResources.forEach((data) => {
249
252
  preloadCustomElement(data, this)
250
253
  .then(() =>
251
- this._handleLoadedResource({ element: data.element, isSuccess: true })
254
+ this._handleLoadedResource({
255
+ element: data.element,
256
+ isSuccess: true,
257
+ }),
252
258
  )
253
259
  .catch(() => {});
254
260
  });
255
261
  }
256
262
 
257
263
  /** Event on resource loaded */
258
- private _handleLoadedResource({
264
+ protected _handleLoadedResource({
259
265
  element,
260
266
  isSuccess,
261
267
  }: NProgressPreloader.IHandleLoadedResourceParameter) {
@@ -48,7 +48,7 @@ function getLoadProgress({
48
48
 
49
49
  export function preloadCustomElement(
50
50
  data: NProgressPreloader.ICustomResourceData,
51
- instance: Module<any, any, any>
51
+ instance: Module<any, any, any>,
52
52
  ) {
53
53
  return new Promise<void>((resolve) => {
54
54
  const { targetProgress } = data;
@@ -1,6 +1,6 @@
1
1
  export function preloadImage(
2
2
  imageProp: HTMLImageElement,
3
- action: (isSuccess: boolean) => void
3
+ action: (isSuccess: boolean) => void,
4
4
  ) {
5
5
  if (imageProp.complete) {
6
6
  action(true);
@@ -1,6 +1,6 @@
1
1
  export function preloadVideo(
2
2
  video: HTMLVideoElement,
3
- action: (isSuccess: boolean) => void
3
+ action: (isSuccess: boolean) => void,
4
4
  ) {
5
5
  if (video.readyState > 0) {
6
6
  action(true);
@@ -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 {
@@ -35,7 +37,7 @@ export class ScrollBar<
35
37
  }
36
38
 
37
39
  /** Scroll container */
38
- private _container: Element | Window | SmoothScroll;
40
+ protected _container: Element | Window | SmoothScroll;
39
41
 
40
42
  /** Scroll container */
41
43
  get container() {
@@ -81,10 +83,10 @@ export class ScrollBar<
81
83
  }
82
84
 
83
85
  /** Horizontal scrollbar */
84
- private _xBar: Bar;
86
+ protected _xBar: Bar;
85
87
 
86
88
  /** Vertical scrollbar */
87
- private _yBar: Bar;
89
+ protected _yBar: Bar;
88
90
 
89
91
  constructor(initialProps?: StaticProps & ChangeableProps, canInit = true) {
90
92
  super(initialProps, false);
@@ -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
@@ -139,7 +141,7 @@ export class ScrollBar<
139
141
  }
140
142
 
141
143
  // Set Module Events
142
- private _setEvents() {
144
+ protected _setEvents() {
143
145
  const { container, props } = this;
144
146
 
145
147
  // default resize handler
@@ -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 {
@@ -127,7 +129,7 @@ export class ScrollView<
127
129
  }
128
130
 
129
131
  /** Set view events */
130
- private _setViewEvents() {
132
+ protected _setViewEvents() {
131
133
  if (!this._isIntersectionObserverSupported) {
132
134
  return;
133
135
  }
@@ -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> = {};