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.
- package/lib/cjs/base/Component/index.js.map +1 -1
- package/lib/cjs/components/AnimationFrame/index.js.map +1 -1
- package/lib/cjs/components/BaseTimeline/index.js.map +1 -1
- package/lib/cjs/components/Ctx2D/index.js.map +1 -1
- package/lib/cjs/components/Ctx2DPrerender/index.js.map +1 -1
- package/lib/cjs/components/CustomCursor/index.js.map +1 -1
- package/lib/cjs/components/DraggerBase/index.js.map +1 -1
- package/lib/cjs/components/DraggerDirection/index.js.map +1 -1
- package/lib/cjs/components/DraggerMove/index.js.map +1 -1
- package/lib/cjs/components/Preloader/index.js.map +1 -1
- package/lib/cjs/components/ProgressPreloader/index.js +4 -1
- package/lib/cjs/components/ProgressPreloader/index.js.map +1 -1
- package/lib/cjs/components/ScrollBar/index.js.map +1 -1
- package/lib/cjs/components/ScrollView/index.js.map +1 -1
- package/lib/cjs/components/SectionScrollProgress/index.js.map +1 -1
- package/lib/cjs/components/SlideProgress/index.js +185 -0
- package/lib/cjs/components/SlideProgress/index.js.map +1 -0
- package/lib/cjs/components/SlideProgress/types.js +3 -0
- package/lib/cjs/components/SlideProgress/types.js.map +1 -0
- package/lib/cjs/components/SmoothScroll/index.js.map +1 -1
- package/lib/cjs/components/SmoothScrollDragPlugin/index.js.map +1 -1
- package/lib/cjs/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
- package/lib/cjs/components/SplitText/index.js.map +1 -1
- package/lib/cjs/components/Timeline/index.js.map +1 -1
- package/lib/cjs/components/index.js +1 -0
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/base/Component/index.js.map +1 -1
- package/lib/esm/components/AnimationFrame/index.js.map +1 -1
- package/lib/esm/components/BaseTimeline/index.js.map +1 -1
- package/lib/esm/components/Ctx2D/index.js.map +1 -1
- package/lib/esm/components/Ctx2DPrerender/index.js.map +1 -1
- package/lib/esm/components/CustomCursor/index.js.map +1 -1
- package/lib/esm/components/DraggerBase/index.js.map +1 -1
- package/lib/esm/components/DraggerDirection/index.js.map +1 -1
- package/lib/esm/components/DraggerMove/index.js.map +1 -1
- package/lib/esm/components/Preloader/index.js.map +1 -1
- package/lib/esm/components/ProgressPreloader/index.js +4 -1
- package/lib/esm/components/ProgressPreloader/index.js.map +1 -1
- package/lib/esm/components/ScrollBar/index.js.map +1 -1
- package/lib/esm/components/ScrollView/index.js.map +1 -1
- package/lib/esm/components/SectionScrollProgress/index.js.map +1 -1
- package/lib/esm/components/SlideProgress/index.js +134 -0
- package/lib/esm/components/SlideProgress/index.js.map +1 -0
- package/lib/esm/components/SlideProgress/types.js +2 -0
- package/lib/esm/components/SlideProgress/types.js.map +1 -0
- package/lib/esm/components/SmoothScroll/index.js.map +1 -1
- package/lib/esm/components/SmoothScrollDragPlugin/index.js.map +1 -1
- package/lib/esm/components/SmoothScrollKeyboardPlugin/index.js.map +1 -1
- package/lib/esm/components/SplitText/index.js.map +1 -1
- package/lib/esm/components/Timeline/index.js.map +1 -1
- package/lib/esm/components/index.js +1 -0
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/base/Component/index.d.ts.map +1 -1
- package/lib/types/components/AnimationFrame/index.d.ts +11 -11
- package/lib/types/components/AnimationFrame/index.d.ts.map +1 -1
- package/lib/types/components/BaseTimeline/index.d.ts +7 -4
- package/lib/types/components/BaseTimeline/index.d.ts.map +1 -1
- package/lib/types/components/Ctx2D/index.d.ts +6 -6
- package/lib/types/components/Ctx2D/index.d.ts.map +1 -1
- package/lib/types/components/Ctx2DPrerender/index.d.ts +1 -1
- package/lib/types/components/Ctx2DPrerender/index.d.ts.map +1 -1
- package/lib/types/components/CustomCursor/index.d.ts +20 -19
- package/lib/types/components/CustomCursor/index.d.ts.map +1 -1
- package/lib/types/components/DraggerBase/index.d.ts +11 -10
- package/lib/types/components/DraggerBase/index.d.ts.map +1 -1
- package/lib/types/components/DraggerDirection/index.d.ts.map +1 -1
- package/lib/types/components/DraggerMove/index.d.ts +1 -1
- package/lib/types/components/DraggerMove/index.d.ts.map +1 -1
- package/lib/types/components/Marquee/index.d.ts +2 -1
- package/lib/types/components/Marquee/index.d.ts.map +1 -1
- package/lib/types/components/Preloader/index.d.ts +7 -7
- package/lib/types/components/Preloader/index.d.ts.map +1 -1
- package/lib/types/components/ProgressPreloader/index.d.ts +11 -9
- package/lib/types/components/ProgressPreloader/index.d.ts.map +1 -1
- package/lib/types/components/ScrollBar/index.d.ts +5 -4
- package/lib/types/components/ScrollBar/index.d.ts.map +1 -1
- package/lib/types/components/ScrollView/index.d.ts +1 -1
- package/lib/types/components/ScrollView/index.d.ts.map +1 -1
- package/lib/types/components/SectionScrollProgress/index.d.ts.map +1 -1
- package/lib/types/components/SlideProgress/index.d.ts +54 -0
- package/lib/types/components/SlideProgress/index.d.ts.map +1 -0
- package/lib/types/components/SlideProgress/types.d.ts +67 -0
- package/lib/types/components/SlideProgress/types.d.ts.map +1 -0
- package/lib/types/components/SmoothScroll/index.d.ts +6 -4
- package/lib/types/components/SmoothScroll/index.d.ts.map +1 -1
- package/lib/types/components/SmoothScrollDragPlugin/index.d.ts +12 -10
- package/lib/types/components/SmoothScrollDragPlugin/index.d.ts.map +1 -1
- package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts +5 -4
- package/lib/types/components/SmoothScrollKeyboardPlugin/index.d.ts.map +1 -1
- package/lib/types/components/SplitText/index.d.ts +13 -13
- package/lib/types/components/SplitText/index.d.ts.map +1 -1
- package/lib/types/components/Timeline/index.d.ts +5 -5
- package/lib/types/components/Timeline/index.d.ts.map +1 -1
- package/lib/types/components/index.d.ts +1 -0
- package/lib/types/components/index.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/Application/events/PageLoad/index.ts +1 -1
- package/src/Application/events/Viewport/index.ts +3 -3
- package/src/Application/index.ts +1 -1
- package/src/base/Callbacks/index.ts +2 -2
- package/src/base/Component/index.ts +4 -2
- package/src/base/Module/index.ts +13 -13
- package/src/base/Module/stories/index.tsx +1 -1
- package/src/base/MutableProps/index.ts +3 -3
- package/src/base/MutableProps/stories/index.tsx +1 -1
- package/src/base/Plugin/index.ts +2 -2
- package/src/components/AnimationFrame/index.ts +19 -16
- package/src/components/BaseTimeline/index.ts +10 -8
- package/src/components/BaseTimeline/stories/Nested.tsx +1 -1
- package/src/components/Ctx2D/index.ts +7 -7
- package/src/components/Ctx2DPrerender/index.ts +6 -3
- package/src/components/CustomCursor/index.ts +30 -28
- package/src/components/DraggerBase/index.ts +20 -18
- package/src/components/DraggerDirection/index.ts +6 -3
- package/src/components/DraggerMove/index.ts +9 -7
- package/src/components/Marquee/index.ts +3 -3
- package/src/components/Preloader/index.ts +12 -10
- package/src/components/ProgressPreloader/index.ts +25 -19
- package/src/components/ProgressPreloader/utils/preloadCustomElement.ts +1 -1
- package/src/components/ProgressPreloader/utils/preloadImage.ts +1 -1
- package/src/components/ProgressPreloader/utils/preloadVideo.ts +1 -1
- package/src/components/ScrollBar/Bar/index.ts +5 -5
- package/src/components/ScrollBar/index.ts +10 -8
- package/src/components/ScrollBar/stories/Default.tsx +1 -1
- package/src/components/ScrollBar/stories/WithInnerScroll.tsx +1 -1
- package/src/components/ScrollBar/stories/WithSmoothScrollComponent.tsx +1 -1
- package/src/components/ScrollBar/stories/index.stories.tsx +2 -2
- package/src/components/ScrollView/index.ts +13 -11
- package/src/components/ScrollView/stories/index.tsx +1 -1
- package/src/components/SectionScrollProgress/index.ts +6 -3
- package/src/components/SectionScrollProgress/stories/index.stories.tsx +1 -1
- package/src/components/SlideProgress/index.ts +226 -0
- package/src/components/SlideProgress/stories/index.stories.tsx +13 -0
- package/src/components/SlideProgress/stories/index.tsx +66 -0
- package/src/components/SlideProgress/types.ts +71 -0
- package/src/components/SmoothScroll/AnimatonFrame.ts +2 -2
- package/src/components/SmoothScroll/Elements.ts +3 -3
- package/src/components/SmoothScroll/index.ts +13 -11
- package/src/components/SmoothScroll/stories/Default.tsx +1 -1
- package/src/components/SmoothScroll/stories/WithHorizontal.tsx +1 -1
- package/src/components/SmoothScroll/stories/WithInnerLerp.tsx +1 -1
- package/src/components/SmoothScroll/stories/index.stories.tsx +2 -2
- package/src/components/SmoothScrollDragPlugin/index.ts +17 -14
- package/src/components/SmoothScrollDragPlugin/stories/index.tsx +1 -1
- package/src/components/SmoothScrollKeyboardPlugin/index.ts +11 -8
- package/src/components/SmoothScrollKeyboardPlugin/stories/index.tsx +1 -1
- package/src/components/SplitText/index.ts +18 -16
- package/src/components/Timeline/index.ts +9 -8
- package/src/components/Timeline/stories/Nested.tsx +1 -1
- package/src/components/index.ts +1 -0
- package/src/utils/common/mergeWithoutArrays.ts +1 -1
- package/src/utils/common/pickObjectProps.ts +1 -1
- package/src/utils/common/times.ts +1 -1
- package/src/utils/image/load.ts +2 -2
- package/src/utils/image/pathsToProps.ts +1 -1
- package/src/utils/listeners/onResize.ts +3 -3
- package/src/utils/math/clampScope.ts +1 -1
- package/src/utils/math/easing.ts +1 -1
- package/src/utils/math/lerp.ts +1 -1
- package/src/utils/math/normalizeNestedScope.ts +1 -1
- package/src/utils/math/wrap.ts +1 -1
- package/src/utils/scroll/getScrollValues.ts +1 -1
- package/src/utils/scroll/onScroll.ts +7 -7
- 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
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
104
|
+
protected _animationFrame?: AnimationFrame;
|
|
102
105
|
|
|
103
106
|
/** Timeline to finish progress animation */
|
|
104
|
-
|
|
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({
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
+
protected _xBar: Bar;
|
|
85
87
|
|
|
86
88
|
/** Vertical scrollbar */
|
|
87
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -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
|
|
16
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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;
|
|
@@ -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
|
|
16
|
-
|
|
17
|
-
|
|
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 {
|
|
@@ -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> = {};
|