vevet 2.13.0 → 2.15.1
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/build/cdn/index.js +1 -1
- package/build/cjs/components/cursor/CustomCursor.js +11 -6
- package/build/cjs/components/scroll/scrollable/ScrollEventsBase.js +11 -8
- package/build/cjs/version.js +1 -1
- package/build/es/components/cursor/CustomCursor.js +10 -5
- package/build/es/components/scroll/scrollable/ScrollEventsBase.js +11 -8
- package/build/es/version.js +1 -1
- package/build/types/components/cursor/CustomCursor.d.ts +10 -16
- package/build/types/components/cursor/CustomCursor.d.ts.map +1 -1
- package/build/types/components/scroll/scrollable/ScrollEventsBase.d.ts +6 -0
- package/build/types/components/scroll/scrollable/ScrollEventsBase.d.ts.map +1 -1
- package/build/types/components/scroll/section/ScrollSectionProgress.d.ts +1 -1
- package/build/types/components/scroll/section/ScrollSectionProgress.d.ts.map +1 -1
- package/build/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/ts/components/cursor/CustomCursor.ts +14 -12
- package/src/ts/components/scroll/scrollable/ScrollEventsBase.ts +17 -7
- package/src/ts/components/scroll/section/ScrollSectionProgress.ts +344 -344
- package/src/ts/version.ts +1 -1
|
@@ -1,344 +1,344 @@
|
|
|
1
|
-
import { selectOne } from 'vevet-dom';
|
|
2
|
-
import PCancelable from 'p-cancelable';
|
|
3
|
-
import { IRemovable } from '../../../utils/types/general';
|
|
4
|
-
import { RequiredModuleProp } from '../../../utils/types/utility';
|
|
5
|
-
import onScroll from '../../../utils/listeners/onScroll';
|
|
6
|
-
import { Component, NComponent } from '../../../base/Component';
|
|
7
|
-
import { NViewport } from '../../../app/events/Viewport';
|
|
8
|
-
import { SmoothScroll } from '../smooth-scroll/SmoothScroll';
|
|
9
|
-
import clampScope from '../../../utils/math/clampScope';
|
|
10
|
-
import getScrollValues from '../../../utils/scroll/getScrollValues';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export namespace NScrollSectionProgress {
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Static properties
|
|
18
|
-
*/
|
|
19
|
-
export interface StaticProp extends NComponent.StaticProp {
|
|
20
|
-
/**
|
|
21
|
-
* The scrollable container
|
|
22
|
-
* @default window
|
|
23
|
-
*/
|
|
24
|
-
container?: string | Element | SmoothScroll | Window;
|
|
25
|
-
/**
|
|
26
|
-
* The scrollable element
|
|
27
|
-
*/
|
|
28
|
-
section: string | Element;
|
|
29
|
-
/**
|
|
30
|
-
* Viewport target on resize
|
|
31
|
-
* @default ''
|
|
32
|
-
*/
|
|
33
|
-
viewportTarget?: keyof NViewport.CallbacksTypes;
|
|
34
|
-
/**
|
|
35
|
-
* @default 0
|
|
36
|
-
*/
|
|
37
|
-
resizeTimeout?: number;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Changeable properties
|
|
42
|
-
*/
|
|
43
|
-
export interface ChangeableProp extends NComponent.ChangeableProp { }
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Available callbacks
|
|
47
|
-
*/
|
|
48
|
-
export interface CallbacksTypes extends NComponent.CallbacksTypes {
|
|
49
|
-
'render': false;
|
|
50
|
-
'resize': false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Elements into viewport
|
|
59
|
-
*/
|
|
60
|
-
export class ScrollSectionProgress <
|
|
61
|
-
StaticProp extends NScrollSectionProgress.StaticProp
|
|
62
|
-
= NScrollSectionProgress.StaticProp,
|
|
63
|
-
ChangeableProp extends NScrollSectionProgress.ChangeableProp
|
|
64
|
-
= NScrollSectionProgress.ChangeableProp,
|
|
65
|
-
CallbacksTypes extends NScrollSectionProgress.CallbacksTypes
|
|
66
|
-
= NScrollSectionProgress.CallbacksTypes,
|
|
67
|
-
> extends Component <
|
|
68
|
-
StaticProp,
|
|
69
|
-
ChangeableProp,
|
|
70
|
-
CallbacksTypes
|
|
71
|
-
> {
|
|
72
|
-
protected _getDefaultProp <
|
|
73
|
-
T extends RequiredModuleProp<StaticProp & ChangeableProp>
|
|
74
|
-
> (): T {
|
|
75
|
-
return {
|
|
76
|
-
...super._getDefaultProp(),
|
|
77
|
-
container: window,
|
|
78
|
-
viewportTarget: '',
|
|
79
|
-
resizeTimeout: 0,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Scroll container
|
|
85
|
-
*/
|
|
86
|
-
protected _scrollContainer: Element | SmoothScroll | Window;
|
|
87
|
-
get scrollContainer () {
|
|
88
|
-
return this._scrollContainer;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Section element
|
|
93
|
-
*/
|
|
94
|
-
protected _section: Element;
|
|
95
|
-
get section () {
|
|
96
|
-
return this._section;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Scroll event
|
|
101
|
-
*/
|
|
102
|
-
protected _scrollEvent?: IRemovable;
|
|
103
|
-
/**
|
|
104
|
-
* Loaded event
|
|
105
|
-
*/
|
|
106
|
-
protected _loadedEvent?: PCancelable<any>;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Scrolling scope
|
|
110
|
-
*/
|
|
111
|
-
protected _scopeScroll: [number, number];
|
|
112
|
-
get scopeScroll () {
|
|
113
|
-
return this._scopeScroll;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 'In' scope relative to the global progress
|
|
118
|
-
*/
|
|
119
|
-
protected _scopeIn: [number, number];
|
|
120
|
-
|
|
121
|
-
return this._scopeIn;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 'Move' scope relative to the global progress
|
|
126
|
-
*/
|
|
127
|
-
protected _scopeMove: [number, number];
|
|
128
|
-
get scopeMove () {
|
|
129
|
-
return this._scopeMove;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 'Move' scope relative to the global progress
|
|
134
|
-
*/
|
|
135
|
-
protected _scopeOut: [number, number];
|
|
136
|
-
get scopeOut () {
|
|
137
|
-
return this._scopeOut;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected _progress: number;
|
|
141
|
-
/**
|
|
142
|
-
* Global progress
|
|
143
|
-
*/
|
|
144
|
-
get progress () {
|
|
145
|
-
return this._progress;
|
|
146
|
-
}
|
|
147
|
-
set progress (val) {
|
|
148
|
-
this._progress = val;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
constructor (
|
|
154
|
-
initialProp?: (StaticProp & ChangeableProp),
|
|
155
|
-
init = true,
|
|
156
|
-
) {
|
|
157
|
-
super(initialProp, false);
|
|
158
|
-
|
|
159
|
-
// get scroll container
|
|
160
|
-
if (typeof this.prop.container === 'string') {
|
|
161
|
-
this._scrollContainer = selectOne(this.prop.container) as Element;
|
|
162
|
-
} else {
|
|
163
|
-
this._scrollContainer = this.prop.container;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// get section element
|
|
167
|
-
if (typeof this.prop.section === 'string') {
|
|
168
|
-
this._section = selectOne(this.prop.section) as Element;
|
|
169
|
-
} else {
|
|
170
|
-
this._section = this.prop.section;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// set defaults
|
|
174
|
-
this._progress = -0.001;
|
|
175
|
-
this._scopeScroll = [0, 0];
|
|
176
|
-
this._scopeIn = [0, 0];
|
|
177
|
-
this._scopeMove = [0, 0];
|
|
178
|
-
this._scopeOut = [0, 0];
|
|
179
|
-
|
|
180
|
-
// initialize the class
|
|
181
|
-
if (init) {
|
|
182
|
-
this.init();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public init () {
|
|
187
|
-
super.init();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Set Module Events
|
|
191
|
-
protected _setEvents () {
|
|
192
|
-
super._setEvents();
|
|
193
|
-
|
|
194
|
-
// set resize events
|
|
195
|
-
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
196
|
-
this.resize();
|
|
197
|
-
}, {
|
|
198
|
-
timeout: this.prop.resizeTimeout,
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// resize on page loaded
|
|
202
|
-
this._loadedEvent = this._app.onPageLoaded();
|
|
203
|
-
this._loadedEvent.then(() => {
|
|
204
|
-
this.resize();
|
|
205
|
-
}).catch(() => {});
|
|
206
|
-
|
|
207
|
-
// set scroll events
|
|
208
|
-
this._scrollEvent = onScroll({
|
|
209
|
-
container: this.prop.container,
|
|
210
|
-
callback: this._handleScroll.bind(this),
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
protected _onPropMutate () {
|
|
215
|
-
super._onPropMutate();
|
|
216
|
-
this.resize();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* 'in' progress
|
|
223
|
-
*/
|
|
224
|
-
get progressIn () {
|
|
225
|
-
return clampScope(
|
|
226
|
-
this.progress,
|
|
227
|
-
this.scopeIn,
|
|
228
|
-
) || 0;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* 'out' progress
|
|
233
|
-
*/
|
|
234
|
-
get progressOut () {
|
|
235
|
-
return clampScope(
|
|
236
|
-
this.progress,
|
|
237
|
-
this.scopeOut,
|
|
238
|
-
) || 0;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* 'move' progress
|
|
243
|
-
*/
|
|
244
|
-
get progressMove () {
|
|
245
|
-
return clampScope(
|
|
246
|
-
this.progress,
|
|
247
|
-
this.scopeMove,
|
|
248
|
-
) || 0;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Handle scroll event
|
|
255
|
-
*/
|
|
256
|
-
protected _handleScroll () {
|
|
257
|
-
// calculate scopes
|
|
258
|
-
const scrollData = getScrollValues(this.scrollContainer);
|
|
259
|
-
if (!scrollData) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
this._render(scrollData);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Resize the scene
|
|
269
|
-
*/
|
|
270
|
-
public resize () {
|
|
271
|
-
// calculate scopes
|
|
272
|
-
const scrollData = getScrollValues(this.scrollContainer);
|
|
273
|
-
if (!scrollData) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// get sizes
|
|
278
|
-
const bounding = this.section.getBoundingClientRect();
|
|
279
|
-
const vHeight = this._app.viewport.height;
|
|
280
|
-
|
|
281
|
-
// calculate scroll scope
|
|
282
|
-
const inStart = scrollData.scrollTop + bounding.top - vHeight;
|
|
283
|
-
const moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
|
|
284
|
-
const scrollLine = moveEnd - inStart;
|
|
285
|
-
this._scopeScroll = [inStart, moveEnd];
|
|
286
|
-
|
|
287
|
-
// calculate scopes
|
|
288
|
-
this._scopeIn = [0, vHeight / scrollLine];
|
|
289
|
-
this._scopeOut = [1 - vHeight / scrollLine, 1];
|
|
290
|
-
this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
|
|
291
|
-
|
|
292
|
-
// launch callbacks
|
|
293
|
-
this.callbacks.tbt('resize', false);
|
|
294
|
-
|
|
295
|
-
// render the scene
|
|
296
|
-
this._render(scrollData, true);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Render the scene
|
|
301
|
-
*/
|
|
302
|
-
protected _render (
|
|
303
|
-
scrollData: ReturnType<typeof getScrollValues>,
|
|
304
|
-
force = false,
|
|
305
|
-
) {
|
|
306
|
-
const canRender = this._canRender(scrollData, force);
|
|
307
|
-
if (!canRender) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
this.callbacks.tbt('render', false);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Check if the section can be rendered
|
|
315
|
-
*/
|
|
316
|
-
protected _canRender (
|
|
317
|
-
scrollData: ReturnType<typeof getScrollValues>,
|
|
318
|
-
force = false,
|
|
319
|
-
) {
|
|
320
|
-
if (!scrollData) {
|
|
321
|
-
return false;
|
|
322
|
-
}
|
|
323
|
-
const { scrollTop } = scrollData;
|
|
324
|
-
const prevProgress = this.progress;
|
|
325
|
-
|
|
326
|
-
const progress = clampScope(
|
|
327
|
-
scrollTop,
|
|
328
|
-
[this._scopeScroll[0], this._scopeScroll[1]],
|
|
329
|
-
) || 0;
|
|
330
|
-
this.progress = progress;
|
|
331
|
-
|
|
332
|
-
return force || (progress !== prevProgress);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Destroy the module
|
|
338
|
-
*/
|
|
339
|
-
protected _destroy () {
|
|
340
|
-
super._destroy();
|
|
341
|
-
this._scrollEvent?.remove();
|
|
342
|
-
this._loadedEvent?.cancel();
|
|
343
|
-
}
|
|
344
|
-
}
|
|
1
|
+
import { selectOne } from 'vevet-dom';
|
|
2
|
+
import PCancelable from 'p-cancelable';
|
|
3
|
+
import { IRemovable } from '../../../utils/types/general';
|
|
4
|
+
import { RequiredModuleProp } from '../../../utils/types/utility';
|
|
5
|
+
import onScroll from '../../../utils/listeners/onScroll';
|
|
6
|
+
import { Component, NComponent } from '../../../base/Component';
|
|
7
|
+
import { NViewport } from '../../../app/events/Viewport';
|
|
8
|
+
import { SmoothScroll } from '../smooth-scroll/SmoothScroll';
|
|
9
|
+
import clampScope from '../../../utils/math/clampScope';
|
|
10
|
+
import getScrollValues from '../../../utils/scroll/getScrollValues';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export namespace NScrollSectionProgress {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Static properties
|
|
18
|
+
*/
|
|
19
|
+
export interface StaticProp extends NComponent.StaticProp {
|
|
20
|
+
/**
|
|
21
|
+
* The scrollable container
|
|
22
|
+
* @default window
|
|
23
|
+
*/
|
|
24
|
+
container?: string | Element | SmoothScroll | Window;
|
|
25
|
+
/**
|
|
26
|
+
* The scrollable element
|
|
27
|
+
*/
|
|
28
|
+
section: string | Element;
|
|
29
|
+
/**
|
|
30
|
+
* Viewport target on resize
|
|
31
|
+
* @default ''
|
|
32
|
+
*/
|
|
33
|
+
viewportTarget?: keyof NViewport.CallbacksTypes;
|
|
34
|
+
/**
|
|
35
|
+
* @default 0
|
|
36
|
+
*/
|
|
37
|
+
resizeTimeout?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Changeable properties
|
|
42
|
+
*/
|
|
43
|
+
export interface ChangeableProp extends NComponent.ChangeableProp { }
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Available callbacks
|
|
47
|
+
*/
|
|
48
|
+
export interface CallbacksTypes extends NComponent.CallbacksTypes {
|
|
49
|
+
'render': false;
|
|
50
|
+
'resize': false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Elements into viewport
|
|
59
|
+
*/
|
|
60
|
+
export class ScrollSectionProgress <
|
|
61
|
+
StaticProp extends NScrollSectionProgress.StaticProp
|
|
62
|
+
= NScrollSectionProgress.StaticProp,
|
|
63
|
+
ChangeableProp extends NScrollSectionProgress.ChangeableProp
|
|
64
|
+
= NScrollSectionProgress.ChangeableProp,
|
|
65
|
+
CallbacksTypes extends NScrollSectionProgress.CallbacksTypes
|
|
66
|
+
= NScrollSectionProgress.CallbacksTypes,
|
|
67
|
+
> extends Component <
|
|
68
|
+
StaticProp,
|
|
69
|
+
ChangeableProp,
|
|
70
|
+
CallbacksTypes
|
|
71
|
+
> {
|
|
72
|
+
protected _getDefaultProp <
|
|
73
|
+
T extends RequiredModuleProp<StaticProp & ChangeableProp>
|
|
74
|
+
> (): T {
|
|
75
|
+
return {
|
|
76
|
+
...super._getDefaultProp(),
|
|
77
|
+
container: window,
|
|
78
|
+
viewportTarget: '',
|
|
79
|
+
resizeTimeout: 0,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Scroll container
|
|
85
|
+
*/
|
|
86
|
+
protected _scrollContainer: Element | SmoothScroll | Window;
|
|
87
|
+
get scrollContainer () {
|
|
88
|
+
return this._scrollContainer;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Section element
|
|
93
|
+
*/
|
|
94
|
+
protected _section: Element;
|
|
95
|
+
get section () {
|
|
96
|
+
return this._section;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Scroll event
|
|
101
|
+
*/
|
|
102
|
+
protected _scrollEvent?: IRemovable;
|
|
103
|
+
/**
|
|
104
|
+
* Loaded event
|
|
105
|
+
*/
|
|
106
|
+
protected _loadedEvent?: PCancelable<any>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Scrolling scope
|
|
110
|
+
*/
|
|
111
|
+
protected _scopeScroll: [number, number];
|
|
112
|
+
get scopeScroll () {
|
|
113
|
+
return this._scopeScroll;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 'In' scope relative to the global progress
|
|
118
|
+
*/
|
|
119
|
+
protected _scopeIn: [number, number];
|
|
120
|
+
get scopeIn () {
|
|
121
|
+
return this._scopeIn;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 'Move' scope relative to the global progress
|
|
126
|
+
*/
|
|
127
|
+
protected _scopeMove: [number, number];
|
|
128
|
+
get scopeMove () {
|
|
129
|
+
return this._scopeMove;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 'Move' scope relative to the global progress
|
|
134
|
+
*/
|
|
135
|
+
protected _scopeOut: [number, number];
|
|
136
|
+
get scopeOut () {
|
|
137
|
+
return this._scopeOut;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected _progress: number;
|
|
141
|
+
/**
|
|
142
|
+
* Global progress
|
|
143
|
+
*/
|
|
144
|
+
get progress () {
|
|
145
|
+
return this._progress;
|
|
146
|
+
}
|
|
147
|
+
set progress (val) {
|
|
148
|
+
this._progress = val;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
constructor (
|
|
154
|
+
initialProp?: (StaticProp & ChangeableProp),
|
|
155
|
+
init = true,
|
|
156
|
+
) {
|
|
157
|
+
super(initialProp, false);
|
|
158
|
+
|
|
159
|
+
// get scroll container
|
|
160
|
+
if (typeof this.prop.container === 'string') {
|
|
161
|
+
this._scrollContainer = selectOne(this.prop.container) as Element;
|
|
162
|
+
} else {
|
|
163
|
+
this._scrollContainer = this.prop.container;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// get section element
|
|
167
|
+
if (typeof this.prop.section === 'string') {
|
|
168
|
+
this._section = selectOne(this.prop.section) as Element;
|
|
169
|
+
} else {
|
|
170
|
+
this._section = this.prop.section;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// set defaults
|
|
174
|
+
this._progress = -0.001;
|
|
175
|
+
this._scopeScroll = [0, 0];
|
|
176
|
+
this._scopeIn = [0, 0];
|
|
177
|
+
this._scopeMove = [0, 0];
|
|
178
|
+
this._scopeOut = [0, 0];
|
|
179
|
+
|
|
180
|
+
// initialize the class
|
|
181
|
+
if (init) {
|
|
182
|
+
this.init();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public init () {
|
|
187
|
+
super.init();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Set Module Events
|
|
191
|
+
protected _setEvents () {
|
|
192
|
+
super._setEvents();
|
|
193
|
+
|
|
194
|
+
// set resize events
|
|
195
|
+
this.addViewportCallback(this.prop.viewportTarget, () => {
|
|
196
|
+
this.resize();
|
|
197
|
+
}, {
|
|
198
|
+
timeout: this.prop.resizeTimeout,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// resize on page loaded
|
|
202
|
+
this._loadedEvent = this._app.onPageLoaded();
|
|
203
|
+
this._loadedEvent.then(() => {
|
|
204
|
+
this.resize();
|
|
205
|
+
}).catch(() => {});
|
|
206
|
+
|
|
207
|
+
// set scroll events
|
|
208
|
+
this._scrollEvent = onScroll({
|
|
209
|
+
container: this.prop.container,
|
|
210
|
+
callback: this._handleScroll.bind(this),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
protected _onPropMutate () {
|
|
215
|
+
super._onPropMutate();
|
|
216
|
+
this.resize();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 'in' progress
|
|
223
|
+
*/
|
|
224
|
+
get progressIn () {
|
|
225
|
+
return clampScope(
|
|
226
|
+
this.progress,
|
|
227
|
+
this.scopeIn,
|
|
228
|
+
) || 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* 'out' progress
|
|
233
|
+
*/
|
|
234
|
+
get progressOut () {
|
|
235
|
+
return clampScope(
|
|
236
|
+
this.progress,
|
|
237
|
+
this.scopeOut,
|
|
238
|
+
) || 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* 'move' progress
|
|
243
|
+
*/
|
|
244
|
+
get progressMove () {
|
|
245
|
+
return clampScope(
|
|
246
|
+
this.progress,
|
|
247
|
+
this.scopeMove,
|
|
248
|
+
) || 0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Handle scroll event
|
|
255
|
+
*/
|
|
256
|
+
protected _handleScroll () {
|
|
257
|
+
// calculate scopes
|
|
258
|
+
const scrollData = getScrollValues(this.scrollContainer);
|
|
259
|
+
if (!scrollData) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this._render(scrollData);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Resize the scene
|
|
269
|
+
*/
|
|
270
|
+
public resize () {
|
|
271
|
+
// calculate scopes
|
|
272
|
+
const scrollData = getScrollValues(this.scrollContainer);
|
|
273
|
+
if (!scrollData) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// get sizes
|
|
278
|
+
const bounding = this.section.getBoundingClientRect();
|
|
279
|
+
const vHeight = this._app.viewport.height;
|
|
280
|
+
|
|
281
|
+
// calculate scroll scope
|
|
282
|
+
const inStart = scrollData.scrollTop + bounding.top - vHeight;
|
|
283
|
+
const moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
|
|
284
|
+
const scrollLine = moveEnd - inStart;
|
|
285
|
+
this._scopeScroll = [inStart, moveEnd];
|
|
286
|
+
|
|
287
|
+
// calculate scopes
|
|
288
|
+
this._scopeIn = [0, vHeight / scrollLine];
|
|
289
|
+
this._scopeOut = [1 - vHeight / scrollLine, 1];
|
|
290
|
+
this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
|
|
291
|
+
|
|
292
|
+
// launch callbacks
|
|
293
|
+
this.callbacks.tbt('resize', false);
|
|
294
|
+
|
|
295
|
+
// render the scene
|
|
296
|
+
this._render(scrollData, true);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Render the scene
|
|
301
|
+
*/
|
|
302
|
+
protected _render (
|
|
303
|
+
scrollData: ReturnType<typeof getScrollValues>,
|
|
304
|
+
force = false,
|
|
305
|
+
) {
|
|
306
|
+
const canRender = this._canRender(scrollData, force);
|
|
307
|
+
if (!canRender) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
this.callbacks.tbt('render', false);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Check if the section can be rendered
|
|
315
|
+
*/
|
|
316
|
+
protected _canRender (
|
|
317
|
+
scrollData: ReturnType<typeof getScrollValues>,
|
|
318
|
+
force = false,
|
|
319
|
+
) {
|
|
320
|
+
if (!scrollData) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
const { scrollTop } = scrollData;
|
|
324
|
+
const prevProgress = this.progress;
|
|
325
|
+
|
|
326
|
+
const progress = clampScope(
|
|
327
|
+
scrollTop,
|
|
328
|
+
[this._scopeScroll[0], this._scopeScroll[1]],
|
|
329
|
+
) || 0;
|
|
330
|
+
this.progress = progress;
|
|
331
|
+
|
|
332
|
+
return force || (progress !== prevProgress);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Destroy the module
|
|
338
|
+
*/
|
|
339
|
+
protected _destroy () {
|
|
340
|
+
super._destroy();
|
|
341
|
+
this._scrollEvent?.remove();
|
|
342
|
+
this._loadedEvent?.cancel();
|
|
343
|
+
}
|
|
344
|
+
}
|
package/src/ts/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '2.
|
|
1
|
+
const version = '2.15.1';
|
|
2
2
|
export default version;
|