vevet 2.12.0 → 2.15.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/build/cdn/index.js +1 -1
- package/build/cjs/components/cursor/CustomCursor.js +139 -40
- package/build/cjs/components/scroll/scrollable/ScrollEventsBase.js +11 -8
- package/build/cjs/version.js +1 -1
- package/build/es/components/cursor/CustomCursor.js +128 -41
- 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 +93 -14
- 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/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/sass/components/cursor/_custom-cursor.scss +10 -10
- package/src/ts/components/cursor/CustomCursor.ts +199 -50
- 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
|
@@ -26,6 +26,16 @@ export declare namespace NCustomCursor {
|
|
|
26
26
|
* Changeable properties
|
|
27
27
|
*/
|
|
28
28
|
interface ChangeableProp extends NComponent.ChangeableProp {
|
|
29
|
+
size?: {
|
|
30
|
+
/**
|
|
31
|
+
* @default 50
|
|
32
|
+
*/
|
|
33
|
+
width?: number;
|
|
34
|
+
/**
|
|
35
|
+
* @default 50
|
|
36
|
+
*/
|
|
37
|
+
height?: number;
|
|
38
|
+
};
|
|
29
39
|
render?: {
|
|
30
40
|
/**
|
|
31
41
|
* Linear interpolation of coordinates. Speed
|
|
@@ -51,6 +61,19 @@ export declare namespace NCustomCursor {
|
|
|
51
61
|
* @default true
|
|
52
62
|
*/
|
|
53
63
|
autoStop?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
hover?: {
|
|
68
|
+
/**
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
sticky?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
autoSize?: boolean;
|
|
76
|
+
};
|
|
54
77
|
}
|
|
55
78
|
/**
|
|
56
79
|
* Available callbacks
|
|
@@ -96,6 +119,27 @@ export declare class CustomCursor<StaticProp extends NCustomCursor.StaticProp =
|
|
|
96
119
|
*/
|
|
97
120
|
get innerCursor(): HTMLElement;
|
|
98
121
|
protected _innerCursor: HTMLElement;
|
|
122
|
+
/**
|
|
123
|
+
* Hovered element
|
|
124
|
+
*/
|
|
125
|
+
protected _hoveredEl?: {
|
|
126
|
+
el: Element;
|
|
127
|
+
width?: number;
|
|
128
|
+
height?: number;
|
|
129
|
+
padding?: number;
|
|
130
|
+
};
|
|
131
|
+
get hoveredEl(): {
|
|
132
|
+
el: Element;
|
|
133
|
+
width?: number;
|
|
134
|
+
height?: number;
|
|
135
|
+
padding?: number;
|
|
136
|
+
};
|
|
137
|
+
set hoveredEl(val: {
|
|
138
|
+
el: Element;
|
|
139
|
+
width?: number;
|
|
140
|
+
height?: number;
|
|
141
|
+
padding?: number;
|
|
142
|
+
});
|
|
99
143
|
/**
|
|
100
144
|
* Animation frame
|
|
101
145
|
*/
|
|
@@ -109,26 +153,44 @@ export declare class CustomCursor<StaticProp extends NCustomCursor.StaticProp =
|
|
|
109
153
|
*/
|
|
110
154
|
protected _canPlay: boolean;
|
|
111
155
|
/**
|
|
112
|
-
* Current
|
|
113
|
-
*/
|
|
114
|
-
get x(): number;
|
|
115
|
-
protected _x: number;
|
|
116
|
-
/**
|
|
117
|
-
* Target coordinate
|
|
156
|
+
* Current cursor coordinates
|
|
118
157
|
*/
|
|
119
|
-
protected
|
|
158
|
+
protected _coords: {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
161
|
+
w: number;
|
|
162
|
+
h: number;
|
|
163
|
+
};
|
|
164
|
+
get coords(): {
|
|
165
|
+
x: number;
|
|
166
|
+
y: number;
|
|
167
|
+
w: number;
|
|
168
|
+
h: number;
|
|
169
|
+
};
|
|
120
170
|
/**
|
|
121
|
-
*
|
|
171
|
+
* Target cursor coordinates
|
|
122
172
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
173
|
+
protected _targetCoords: {
|
|
174
|
+
x: number;
|
|
175
|
+
y: number;
|
|
176
|
+
w: number;
|
|
177
|
+
h: number;
|
|
178
|
+
};
|
|
179
|
+
get targetCoords(): {
|
|
180
|
+
x: number;
|
|
181
|
+
y: number;
|
|
182
|
+
w: number;
|
|
183
|
+
h: number;
|
|
184
|
+
};
|
|
129
185
|
constructor(initialProp?: (StaticProp & ChangeableProp), init?: boolean);
|
|
130
186
|
protected _constructor(): void;
|
|
131
187
|
protected _setEvents(): void;
|
|
188
|
+
/**
|
|
189
|
+
* Set hover events on an element
|
|
190
|
+
*/
|
|
191
|
+
addHoverEl(settings: NonNullable<CustomCursor['hoveredEl']>, enterTimeout?: number): {
|
|
192
|
+
remove: () => void;
|
|
193
|
+
};
|
|
132
194
|
/**
|
|
133
195
|
* Create custom cursor
|
|
134
196
|
*/
|
|
@@ -165,6 +227,23 @@ export declare class CustomCursor<StaticProp extends NCustomCursor.StaticProp =
|
|
|
165
227
|
* Render the scene
|
|
166
228
|
*/
|
|
167
229
|
render(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Recalculate current coordinates
|
|
232
|
+
*/
|
|
233
|
+
protected _calcCoords(): void;
|
|
234
|
+
/**
|
|
235
|
+
* Linear interpolation
|
|
236
|
+
*/
|
|
237
|
+
protected _lerp(current: number, target: number): number;
|
|
238
|
+
/**
|
|
239
|
+
* Render cursor elements
|
|
240
|
+
*/
|
|
241
|
+
protected _renderElements(): {
|
|
242
|
+
x: number;
|
|
243
|
+
y: number;
|
|
244
|
+
w: number;
|
|
245
|
+
h: number;
|
|
246
|
+
};
|
|
168
247
|
/**
|
|
169
248
|
* Enable cursor
|
|
170
249
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomCursor.d.ts","sourceRoot":"","sources":["../../../../src/ts/components/cursor/CustomCursor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomCursor.d.ts","sourceRoot":"","sources":["../../../../src/ts/components/cursor/CustomCursor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAM/D,yBAAiB,aAAa,CAAC;IAE3B;;OAEG;IACH,UAAiB,UAAW,SAAQ,UAAU,CAAC,UAAU;QACrD;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;QACtC;;;WAGG;QACH,GAAG,CAAC,EAAE,OAAO,CAAC;QACd;;;WAGG;QACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC9B;IAED;;OAEG;IACH,UAAiB,cAAe,SAAQ,UAAU,CAAC,cAAc;QAC7D,IAAI,CAAC,EAAE;YACH;;eAEG;YACH,KAAK,CAAC,EAAE,MAAM,CAAC;YACf;;eAEG;YACH,MAAM,CAAC,EAAE,MAAM,CAAC;SACnB,CAAC;QACF,MAAM,CAAC,EAAE;YACL;;;eAGG;YACH,IAAI,CAAC,EAAE,MAAM,CAAC;YACd;;;;;eAKG;YACH,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;YAC7B;;;;eAIG;YACH,aAAa,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;IACH,SAAS,CAAC,iBAAiB;IAI3B;;OAEG;IACH,SAAS,CAAC,gBAAgB,CACtB,GAAG,EAAE,UAAU;IAYnB;;OAEG;IACH,SAAS,CAAC,gBAAgB,CACtB,GAAG,EAAE,UAAU;IAQnB;;OAEG;IACH,SAAS,CAAC,cAAc;IAKxB;;OAEG;IACH,SAAS,CAAC,iBAAiB;IAM3B;;OAEG;IACI,MAAM;IAoBb;;OAEG;IACH,SAAS,CAAC,WAAW;IAOrB;;OAEG;IACH,SAAS,CAAC,KAAK,CACX,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAgBlB;;OAEG;IACH,SAAS,CAAC,eAAe;;;;;;IA0BzB;;OAEG;IACI,MAAM;IAWb;;OAEG;IACI,OAAO;IAYd;;OAEG;IACH,SAAS,CAAC,QAAQ;CAKrB"}
|
|
@@ -11,6 +11,12 @@ export declare namespace NScrollEventsBase {
|
|
|
11
11
|
* @default window
|
|
12
12
|
*/
|
|
13
13
|
container?: string | Element | SmoothScroll | Window;
|
|
14
|
+
/**
|
|
15
|
+
* Intersection root element. If false, the element is found
|
|
16
|
+
* automatically
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
intersectionRoot?: false | null | Element;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Changeable properties
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollEventsBase.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollEventsBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAI7D,yBAAiB,iBAAiB,CAAC;IAE/B;;OAEG;IACH,UAAiB,UAAW,SAAQ,UAAU,CAAC,UAAU;QACrD;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ScrollEventsBase.d.ts","sourceRoot":"","sources":["../../../../../src/ts/components/scroll/scrollable/ScrollEventsBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAI7D,yBAAiB,iBAAiB,CAAC;IAE/B;;OAEG;IACH,UAAiB,UAAW,SAAQ,UAAU,CAAC,UAAU;QACrD;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;QACrD;;;;WAIG;QACH,gBAAgB,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC;KAC7C;IAED;;OAEG;IACH,UAAiB,cAAe,SAAQ,UAAU,CAAC,cAAc;KAAI;IAErE;;OAEG;IACH,UAAiB,cAAe,SAAQ,UAAU,CAAC,cAAc;KAAI;IAErE;;OAEG;IACH,UAAiB,YAAY;QACzB,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAClB;CAEJ;AAID;;GAEG;AACH,8BAAsB,gBAAgB,CAClC,UAAU,SAAS,iBAAiB,CAAC,UAAU,GAAG,iBAAiB,CAAC,UAAU,EAC9E,cAAc,SAAS,iBAAiB,CAAC,cAAc,GAAG,iBAAiB,CAAC,cAAc,EAC1F,cAAc,SAAS,iBAAiB,CAAC,cAAc,GAAG,iBAAiB,CAAC,cAAc,CAC5F,SAAQ,SAAS,CACf,UAAU,EACV,cAAc,EACd,cAAc,CACjB;IACG,SAAS,CAAC,eAAe,CACrB,CAAC,SAAS,kBAAkB,CAAC,UAAU,GAAG,cAAc,CAAC,KACvD,CAAC;IAUP;;OAEG;IACH,SAAS,CAAC,gBAAgB,EAAE,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;IAC5D,IAAI,eAAe,kPAElB;IACD,IAAI,iBAAiB,yOAKpB;IAED;;OAEG;IACH,SAAS,KAAK,SAAS,YAStB;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,YAY7B;IAED;;OAEG;IACH,SAAS,KAAK,uBAAuB,IAAK,iBAAiB,CAAC,YAAY,CAgBvE;gBAKG,WAAW,CAAC,EAAE,CAAC,UAAU,GAAG,cAAc,CAAC,EAC3C,IAAI,UAAO;CAgBlB"}
|
package/build/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
@import '../../mixins/index';
|
|
2
2
|
|
|
3
|
-
$custom-cursor-
|
|
4
|
-
$custom-cursor-
|
|
5
|
-
$custom-cursor-
|
|
6
|
-
$custom-cursor-
|
|
7
|
-
$custom-cursor-color: #000;
|
|
3
|
+
$custom-cursor-alpha-duration: 0.25s !default;
|
|
4
|
+
$custom-cursor-scale-duration: 0.5s !default;
|
|
5
|
+
$custom-cursor-alpha: 0.5 !default;
|
|
6
|
+
$custom-cursor-color: #000 !default;
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
|
|
@@ -20,6 +19,8 @@ $custom-cursor-color: #000;
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
.#{$prefix}custom-cursor {
|
|
22
|
+
--cursor-w: 50px;
|
|
23
|
+
--cursor-h: 50px;
|
|
23
24
|
|
|
24
25
|
&.in-window {
|
|
25
26
|
position: fixed;
|
|
@@ -43,11 +44,10 @@ $custom-cursor-color: #000;
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
&__inner {
|
|
46
|
-
width:
|
|
47
|
-
height:
|
|
48
|
-
margin-
|
|
49
|
-
margin-
|
|
50
|
-
border-radius: 50%;
|
|
47
|
+
width: var(--cursor-w);
|
|
48
|
+
height: var(--cursor-h);
|
|
49
|
+
margin-left: calc(var(--cursor-w) / -2);
|
|
50
|
+
margin-top: calc(var(--cursor-h) / -2);
|
|
51
51
|
|
|
52
52
|
background-color: $custom-cursor-color;
|
|
53
53
|
opacity: $custom-cursor-alpha;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createElement, selectOne } from 'vevet-dom';
|
|
1
|
+
import { addEventListener, createElement, selectOne } from 'vevet-dom';
|
|
2
2
|
import { AnimationFrame } from '../animation-frame/AnimationFrame';
|
|
3
3
|
import { Component, NComponent } from '../../base/Component';
|
|
4
4
|
import { RequiredModuleProp } from '../../utils/types/utility';
|
|
5
5
|
import lerp from '../../utils/math/lerp';
|
|
6
|
+
import { timeoutCallback } from '../../utils/common';
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
@@ -33,6 +34,16 @@ export namespace NCustomCursor {
|
|
|
33
34
|
* Changeable properties
|
|
34
35
|
*/
|
|
35
36
|
export interface ChangeableProp extends NComponent.ChangeableProp {
|
|
37
|
+
size?: {
|
|
38
|
+
/**
|
|
39
|
+
* @default 50
|
|
40
|
+
*/
|
|
41
|
+
width?: number;
|
|
42
|
+
/**
|
|
43
|
+
* @default 50
|
|
44
|
+
*/
|
|
45
|
+
height?: number;
|
|
46
|
+
};
|
|
36
47
|
render?: {
|
|
37
48
|
/**
|
|
38
49
|
* Linear interpolation of coordinates. Speed
|
|
@@ -52,12 +63,25 @@ export namespace NCustomCursor {
|
|
|
52
63
|
* @default false
|
|
53
64
|
*/
|
|
54
65
|
normalizeLerp?: boolean;
|
|
55
|
-
}
|
|
66
|
+
};
|
|
56
67
|
/**
|
|
57
68
|
* Automatically stop rendering after the target and current values are approximated.
|
|
58
69
|
* @default true
|
|
59
70
|
*/
|
|
60
71
|
autoStop?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
hover?: {
|
|
76
|
+
/**
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
sticky?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
autoSize?: boolean;
|
|
84
|
+
};
|
|
61
85
|
}
|
|
62
86
|
|
|
63
87
|
/**
|
|
@@ -98,11 +122,19 @@ export class CustomCursor <
|
|
|
98
122
|
container: window,
|
|
99
123
|
run: true,
|
|
100
124
|
hideNativeCursor: false,
|
|
125
|
+
size: {
|
|
126
|
+
width: 50,
|
|
127
|
+
height: 50,
|
|
128
|
+
},
|
|
101
129
|
render: {
|
|
102
130
|
lerp: 0.2,
|
|
103
131
|
lerpToFixed: 2,
|
|
104
132
|
normalizeLerp: false,
|
|
105
133
|
},
|
|
134
|
+
hover: {
|
|
135
|
+
sticky: false,
|
|
136
|
+
autoSize: false,
|
|
137
|
+
},
|
|
106
138
|
autoStop: true,
|
|
107
139
|
};
|
|
108
140
|
}
|
|
@@ -157,6 +189,22 @@ export class CustomCursor <
|
|
|
157
189
|
}
|
|
158
190
|
protected _innerCursor!: HTMLElement;
|
|
159
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Hovered element
|
|
194
|
+
*/
|
|
195
|
+
protected _hoveredEl?: {
|
|
196
|
+
el: Element;
|
|
197
|
+
width?: number;
|
|
198
|
+
height?: number;
|
|
199
|
+
padding?: number;
|
|
200
|
+
};
|
|
201
|
+
get hoveredEl () {
|
|
202
|
+
return this._hoveredEl;
|
|
203
|
+
}
|
|
204
|
+
set hoveredEl (val) {
|
|
205
|
+
this._hoveredEl = val;
|
|
206
|
+
}
|
|
207
|
+
|
|
160
208
|
|
|
161
209
|
|
|
162
210
|
/**
|
|
@@ -173,28 +221,56 @@ export class CustomCursor <
|
|
|
173
221
|
protected _canPlay: boolean;
|
|
174
222
|
|
|
175
223
|
/**
|
|
176
|
-
* Current
|
|
224
|
+
* Current cursor coordinates
|
|
177
225
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
226
|
+
protected _coords: {
|
|
227
|
+
x: number;
|
|
228
|
+
y: number;
|
|
229
|
+
w: number;
|
|
230
|
+
h: number;
|
|
231
|
+
};
|
|
232
|
+
get coords () {
|
|
233
|
+
return this._coords;
|
|
180
234
|
}
|
|
181
|
-
protected _x: number;
|
|
182
|
-
/**
|
|
183
|
-
* Target coordinate
|
|
184
|
-
*/
|
|
185
|
-
protected _xTarget: number;
|
|
186
235
|
|
|
187
236
|
/**
|
|
188
|
-
*
|
|
237
|
+
* Target cursor coordinates
|
|
189
238
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
239
|
+
protected _targetCoords: {
|
|
240
|
+
x: number;
|
|
241
|
+
y: number;
|
|
242
|
+
w: number;
|
|
243
|
+
h: number;
|
|
244
|
+
};
|
|
245
|
+
get targetCoords () {
|
|
246
|
+
const { hoveredEl, prop } = this;
|
|
247
|
+
const sizes = prop.size;
|
|
248
|
+
|
|
249
|
+
let { x } = this._targetCoords;
|
|
250
|
+
let { y } = this._targetCoords;
|
|
251
|
+
let w = sizes.width;
|
|
252
|
+
let h = sizes.height;
|
|
253
|
+
let padding = 0;
|
|
254
|
+
if (hoveredEl) {
|
|
255
|
+
const bounding = hoveredEl.el.getBoundingClientRect();
|
|
256
|
+
if (prop.hover.sticky) {
|
|
257
|
+
x = bounding.left + bounding.width / 2;
|
|
258
|
+
y = bounding.top + bounding.height / 2;
|
|
259
|
+
}
|
|
260
|
+
if (prop.hover.autoSize) {
|
|
261
|
+
w = this.hoveredEl?.width || bounding.width;
|
|
262
|
+
h = this.hoveredEl?.height || bounding.height;
|
|
263
|
+
padding = this.hoveredEl?.padding || 0;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
w += padding * 2;
|
|
268
|
+
h += padding * 2;
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
x, y, w, h,
|
|
272
|
+
};
|
|
192
273
|
}
|
|
193
|
-
protected _y: number;
|
|
194
|
-
/**
|
|
195
|
-
* Target coordinate
|
|
196
|
-
*/
|
|
197
|
-
protected _yTarget: number;
|
|
198
274
|
|
|
199
275
|
|
|
200
276
|
|
|
@@ -214,10 +290,12 @@ export class CustomCursor <
|
|
|
214
290
|
this._containerIsWindow = container instanceof Window;
|
|
215
291
|
|
|
216
292
|
// set default vars
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.
|
|
293
|
+
this._coords = {
|
|
294
|
+
x: 0, y: 0, w: 0, h: 0,
|
|
295
|
+
};
|
|
296
|
+
this._targetCoords = {
|
|
297
|
+
x: 0, y: 0, w: 0, h: 0,
|
|
298
|
+
};
|
|
221
299
|
this._currentFPS = 60;
|
|
222
300
|
this._canPlay = this.prop.run;
|
|
223
301
|
|
|
@@ -260,6 +338,40 @@ export class CustomCursor <
|
|
|
260
338
|
this.addEventListeners(window, 'blur', this._handleWindowBlur.bind(this));
|
|
261
339
|
}
|
|
262
340
|
|
|
341
|
+
/**
|
|
342
|
+
* Set hover events on an element
|
|
343
|
+
*/
|
|
344
|
+
public addHoverEl (
|
|
345
|
+
settings: NonNullable<CustomCursor['hoveredEl']>,
|
|
346
|
+
enterTimeout = 100,
|
|
347
|
+
) {
|
|
348
|
+
const { el } = settings;
|
|
349
|
+
|
|
350
|
+
let timeout: ReturnType<typeof timeoutCallback> | undefined;
|
|
351
|
+
const mouseEnter = addEventListener(el, 'mouseenter', () => {
|
|
352
|
+
timeout = timeoutCallback(() => {
|
|
353
|
+
this.hoveredEl = { ...settings };
|
|
354
|
+
}, enterTimeout);
|
|
355
|
+
});
|
|
356
|
+
const mouseLeave = addEventListener(el, 'mouseleave', () => {
|
|
357
|
+
this.hoveredEl = undefined;
|
|
358
|
+
if (timeout) {
|
|
359
|
+
timeout.clear();
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
remove: () => {
|
|
365
|
+
if (this.hoveredEl?.el === el) {
|
|
366
|
+
this.hoveredEl = undefined;
|
|
367
|
+
}
|
|
368
|
+
mouseEnter.remove();
|
|
369
|
+
mouseLeave.remove();
|
|
370
|
+
timeout?.clear();
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
263
375
|
|
|
264
376
|
|
|
265
377
|
/**
|
|
@@ -316,10 +428,10 @@ export class CustomCursor <
|
|
|
316
428
|
evt: MouseEvent,
|
|
317
429
|
) {
|
|
318
430
|
// update coordinates
|
|
319
|
-
this.
|
|
320
|
-
this.
|
|
321
|
-
this.
|
|
322
|
-
this.
|
|
431
|
+
this._coords.x = evt.clientX;
|
|
432
|
+
this._coords.y = evt.clientY;
|
|
433
|
+
this._targetCoords.x = evt.clientX;
|
|
434
|
+
this._targetCoords.y = evt.clientY;
|
|
323
435
|
// set classes
|
|
324
436
|
this.outerCursor.classList.add('in-action');
|
|
325
437
|
}
|
|
@@ -337,8 +449,8 @@ export class CustomCursor <
|
|
|
337
449
|
protected _handleMouseMove (
|
|
338
450
|
evt: MouseEvent,
|
|
339
451
|
) {
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
452
|
+
this._targetCoords.x = evt.clientX;
|
|
453
|
+
this._targetCoords.y = evt.clientY;
|
|
342
454
|
// set classes
|
|
343
455
|
this.outerCursor.classList.add('in-action');
|
|
344
456
|
// launch animation
|
|
@@ -381,24 +493,66 @@ export class CustomCursor <
|
|
|
381
493
|
*/
|
|
382
494
|
public render () {
|
|
383
495
|
// props
|
|
384
|
-
const { prop } = this;
|
|
385
|
-
|
|
386
|
-
|
|
496
|
+
const { prop, targetCoords } = this;
|
|
497
|
+
|
|
498
|
+
this._calcCoords();
|
|
499
|
+
const realCoords = this._renderElements();
|
|
500
|
+
|
|
501
|
+
// auto stop
|
|
502
|
+
if (
|
|
503
|
+
prop.autoStop
|
|
504
|
+
&& this.coords.x === targetCoords.x && this.coords.y === targetCoords.y
|
|
505
|
+
&& this.coords.w === targetCoords.w && this.coords.h === targetCoords.h
|
|
506
|
+
) {
|
|
507
|
+
this._animationFrame.pause();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// launch render events
|
|
511
|
+
this._callbacks.tbt('render', realCoords);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Recalculate current coordinates
|
|
516
|
+
*/
|
|
517
|
+
protected _calcCoords () {
|
|
518
|
+
this._coords.x = this._lerp(this._coords.x, this.targetCoords.x);
|
|
519
|
+
this._coords.y = this._lerp(this._coords.y, this.targetCoords.y);
|
|
520
|
+
this._coords.w = this._lerp(this._coords.w, this.targetCoords.w);
|
|
521
|
+
this._coords.h = this._lerp(this._coords.h, this.targetCoords.h);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Linear interpolation
|
|
526
|
+
*/
|
|
527
|
+
protected _lerp (
|
|
528
|
+
current: number,
|
|
529
|
+
target: number,
|
|
530
|
+
) {
|
|
531
|
+
const { normalizeLerp, lerp: ease, lerpToFixed } = this.prop.render;
|
|
532
|
+
|
|
387
533
|
const fpsMultiplier = normalizeLerp ? 60 / this._currentFPS : 1;
|
|
534
|
+
let val = lerp(current, target, ease * fpsMultiplier, 0.02);
|
|
388
535
|
|
|
389
|
-
// interpolate coordinates
|
|
390
|
-
this._x = lerp(this._x, this._xTarget, ease * fpsMultiplier, 0.02);
|
|
391
|
-
this._y = lerp(this._y, this._yTarget, ease * fpsMultiplier, 0.02);
|
|
392
536
|
// round the values
|
|
393
537
|
if (typeof lerpToFixed === 'number') {
|
|
394
538
|
const fixed = Math.round(Math.abs(lerpToFixed));
|
|
395
|
-
|
|
396
|
-
this._y = parseFloat(this._y.toFixed(fixed));
|
|
539
|
+
val = parseFloat(val.toFixed(fixed));
|
|
397
540
|
}
|
|
398
541
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
542
|
+
return val;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Render cursor elements
|
|
547
|
+
*/
|
|
548
|
+
protected _renderElements () {
|
|
549
|
+
const { domContainer, outerCursor } = this;
|
|
550
|
+
|
|
551
|
+
// calculate real coordinates
|
|
552
|
+
let {
|
|
553
|
+
x, y,
|
|
554
|
+
} = this.coords;
|
|
555
|
+
const { w, h } = this.coords;
|
|
402
556
|
if (!this._containerIsWindow) {
|
|
403
557
|
const bounding = domContainer.getBoundingClientRect();
|
|
404
558
|
x -= bounding.left;
|
|
@@ -406,18 +560,13 @@ export class CustomCursor <
|
|
|
406
560
|
}
|
|
407
561
|
|
|
408
562
|
// update dom coordinates
|
|
409
|
-
|
|
563
|
+
outerCursor.style.transform = `translate(${x}px, ${y}px)`;
|
|
564
|
+
outerCursor.style.setProperty('--cursor-w', `${w}px`);
|
|
565
|
+
outerCursor.style.setProperty('--cursor-h', `${h}px`);
|
|
410
566
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
&& this._x === this._xTarget && this._y === this._yTarget
|
|
415
|
-
) {
|
|
416
|
-
this._animationFrame.pause();
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// launch render events
|
|
420
|
-
this._callbacks.tbt('render', { x, y });
|
|
567
|
+
return {
|
|
568
|
+
x, y, w, h,
|
|
569
|
+
};
|
|
421
570
|
}
|
|
422
571
|
|
|
423
572
|
|
|
@@ -16,6 +16,12 @@ export namespace NScrollEventsBase {
|
|
|
16
16
|
* @default window
|
|
17
17
|
*/
|
|
18
18
|
container?: string | Element | SmoothScroll | Window;
|
|
19
|
+
/**
|
|
20
|
+
* Intersection root element. If false, the element is found
|
|
21
|
+
* automatically
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
intersectionRoot?: false | null | Element;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
/**
|
|
@@ -60,6 +66,7 @@ export abstract class ScrollEventsBase <
|
|
|
60
66
|
return {
|
|
61
67
|
...super._getDefaultProp(),
|
|
62
68
|
container: window,
|
|
69
|
+
intersectionRoot: false,
|
|
63
70
|
};
|
|
64
71
|
}
|
|
65
72
|
|
|
@@ -97,14 +104,17 @@ export abstract class ScrollEventsBase <
|
|
|
97
104
|
* Used as a "root" for IntersectionObserver
|
|
98
105
|
*/
|
|
99
106
|
protected get intersectionRoot () {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
if (this.prop.intersectionRoot === false) {
|
|
108
|
+
const { scrollContainer } = this;
|
|
109
|
+
if (scrollContainer instanceof Window) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (scrollContainer instanceof Element) {
|
|
113
|
+
return scrollContainer;
|
|
114
|
+
}
|
|
115
|
+
return scrollContainer.outer;
|
|
103
116
|
}
|
|
104
|
-
|
|
105
|
-
return scrollContainer;
|
|
106
|
-
}
|
|
107
|
-
return scrollContainer.outer;
|
|
117
|
+
return this.prop.intersectionRoot;
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
/**
|