@studiometa/js-toolkit 2.0.0-alpha.8 → 2.0.0-beta.10
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/Base/index.d.ts +53 -2
- package/Base/index.js +153 -46
- package/Base/managers/ChildrenManager.js +22 -4
- package/Base/managers/EventsManager.d.ts +3 -1
- package/Base/managers/EventsManager.js +38 -4
- package/Base/managers/OptionsManager.d.ts +2 -0
- package/Base/managers/OptionsManager.js +17 -1
- package/Base/managers/RefsManager.d.ts +2 -0
- package/Base/managers/RefsManager.js +27 -4
- package/Base/managers/ServicesManager.d.ts +36 -4
- package/Base/managers/ServicesManager.js +33 -7
- package/Base/utils.d.ts +0 -8
- package/Base/utils.js +0 -25
- package/README.md +13 -60
- package/decorators/index.d.ts +8 -7
- package/decorators/index.js +8 -7
- package/decorators/withBreakpointObserver.js +2 -2
- package/decorators/withDrag.d.ts +3 -3
- package/decorators/withDrag.js +14 -14
- package/decorators/withIntersectionObserver.js +5 -7
- package/decorators/withMountWhenInView.d.ts +4 -4
- package/decorators/withMountWhenInView.js +13 -6
- package/decorators/withScrolledInView.d.ts +17 -0
- package/decorators/withScrolledInView.js +94 -0
- package/decorators/withVue2.d.ts +7 -0
- package/decorators/withVue2.js +45 -0
- package/helpers/index.d.ts +4 -5
- package/helpers/index.js +4 -5
- package/index.d.ts +4 -19
- package/index.js +4 -5
- package/index.modern.js +1 -1
- package/index.umd.js +1 -1
- package/package.json +1 -1
- package/services/Service.d.ts +22 -17
- package/services/Service.js +12 -7
- package/services/drag.d.ts +5 -19
- package/services/drag.js +82 -105
- package/services/index.d.ts +13 -10
- package/services/index.js +7 -8
- package/services/key.d.ts +4 -13
- package/services/key.js +55 -56
- package/services/load.d.ts +3 -13
- package/services/load.js +32 -26
- package/services/pointer.d.ts +4 -13
- package/services/pointer.js +61 -64
- package/services/raf.d.ts +3 -13
- package/services/raf.js +22 -25
- package/services/resize.d.ts +3 -13
- package/services/resize.js +48 -30
- package/services/scroll.d.ts +3 -13
- package/services/scroll.js +65 -61
- package/utils/collide/index.d.ts +6 -7
- package/utils/collide/index.js +6 -7
- package/utils/css/index.d.ts +4 -5
- package/utils/css/index.js +6 -5
- package/utils/css/transition.js +2 -2
- package/utils/history.d.ts +6 -6
- package/utils/history.js +8 -4
- package/utils/index.d.ts +11 -13
- package/utils/index.js +11 -13
- package/utils/math/damp.d.ts +6 -5
- package/utils/math/damp.js +2 -1
- package/utils/math/ease.d.ts +78 -0
- package/utils/math/ease.js +41 -0
- package/utils/math/index.d.ts +8 -7
- package/utils/math/index.js +8 -7
- package/utils/math/inertiaFinalValue.d.ts +2 -2
- package/utils/math/inertiaFinalValue.js +4 -4
- package/utils/object/getAllProperties.js +1 -1
- package/utils/object/index.d.ts +3 -4
- package/utils/object/index.js +3 -4
- package/utils/scrollTo.d.ts +11 -0
- package/utils/scrollTo.js +75 -0
- package/utils/string/index.d.ts +10 -11
- package/utils/string/index.js +10 -11
package/services/pointer.js
CHANGED
|
@@ -9,17 +9,32 @@ class Pointer extends Service {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super(...arguments);
|
|
11
11
|
|
|
12
|
-
_defineProperty(this, "
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
_defineProperty(this, "props", {
|
|
13
|
+
event: null,
|
|
14
|
+
isDown: false,
|
|
15
|
+
x: window.innerWidth / 2,
|
|
16
|
+
y: window.innerHeight / 2,
|
|
17
|
+
changed: {
|
|
18
|
+
x: false,
|
|
19
|
+
y: false
|
|
20
|
+
},
|
|
21
|
+
last: {
|
|
22
|
+
x: window.innerWidth / 2,
|
|
23
|
+
y: window.innerHeight / 2
|
|
24
|
+
},
|
|
25
|
+
delta: {
|
|
26
|
+
x: 0,
|
|
27
|
+
y: 0
|
|
28
|
+
},
|
|
29
|
+
progress: {
|
|
30
|
+
x: 0.5,
|
|
31
|
+
y: 0.5
|
|
32
|
+
},
|
|
33
|
+
max: {
|
|
34
|
+
x: window.innerWidth,
|
|
35
|
+
y: window.innerHeight
|
|
36
|
+
}
|
|
37
|
+
});
|
|
23
38
|
|
|
24
39
|
_defineProperty(this, "hasRaf", false);
|
|
25
40
|
}
|
|
@@ -73,86 +88,68 @@ class Pointer extends Service {
|
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
handler(event) {
|
|
76
|
-
this.
|
|
91
|
+
this.updateProps(event);
|
|
77
92
|
this.trigger(this.props);
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
downHandler() {
|
|
81
|
-
this.isDown = true;
|
|
96
|
+
this.props.isDown = true;
|
|
82
97
|
this.trigger(this.props);
|
|
83
98
|
}
|
|
84
99
|
|
|
85
100
|
upHandler() {
|
|
86
|
-
this.isDown = false;
|
|
101
|
+
this.props.isDown = false;
|
|
87
102
|
this.trigger(this.props);
|
|
88
103
|
}
|
|
89
104
|
|
|
90
|
-
|
|
105
|
+
updateProps(event) {
|
|
91
106
|
var _event$touches$, _event$touches$2;
|
|
92
107
|
|
|
93
|
-
this.event = event;
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
this.props.event = event;
|
|
109
|
+
var yLast = this.props.y;
|
|
110
|
+
var xLast = this.props.x;
|
|
96
111
|
var y = isTouchEvent(event) ? (_event$touches$ = event.touches[0]) === null || _event$touches$ === void 0 ? void 0 : _event$touches$.clientY : event.clientY;
|
|
97
112
|
|
|
98
|
-
if (y !== this.y) {
|
|
99
|
-
this.y = y;
|
|
113
|
+
if (y !== this.props.y) {
|
|
114
|
+
this.props.y = y;
|
|
100
115
|
}
|
|
101
116
|
|
|
102
117
|
var x = isTouchEvent(event) ? (_event$touches$2 = event.touches[0]) === null || _event$touches$2 === void 0 ? void 0 : _event$touches$2.clientX : event.clientX;
|
|
103
118
|
|
|
104
|
-
if (x !== this.x) {
|
|
105
|
-
this.x = x;
|
|
119
|
+
if (x !== this.props.x) {
|
|
120
|
+
this.props.x = x;
|
|
106
121
|
}
|
|
107
|
-
}
|
|
108
122
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
x: this.xLast,
|
|
121
|
-
y: this.yLast
|
|
122
|
-
},
|
|
123
|
-
delta: {
|
|
124
|
-
x: this.x - this.xLast,
|
|
125
|
-
y: this.y - this.yLast
|
|
126
|
-
},
|
|
127
|
-
progress: {
|
|
128
|
-
x: this.x / window.innerWidth,
|
|
129
|
-
y: this.y / window.innerHeight
|
|
130
|
-
},
|
|
131
|
-
max: {
|
|
132
|
-
x: window.innerWidth,
|
|
133
|
-
y: window.innerHeight
|
|
134
|
-
}
|
|
135
|
-
};
|
|
123
|
+
this.props.changed.x = this.props.x !== xLast;
|
|
124
|
+
this.props.changed.y = this.props.y !== yLast;
|
|
125
|
+
this.props.last.x = xLast;
|
|
126
|
+
this.props.last.y = yLast;
|
|
127
|
+
this.props.delta.x = this.props.x - xLast;
|
|
128
|
+
this.props.delta.y = this.props.y - yLast;
|
|
129
|
+
this.props.max.x = window.innerWidth;
|
|
130
|
+
this.props.max.y = window.innerHeight;
|
|
131
|
+
this.props.progress.x = this.props.x / this.props.max.x;
|
|
132
|
+
this.props.progress.y = this.props.y / this.props.max.y;
|
|
133
|
+
return this.props;
|
|
136
134
|
}
|
|
137
135
|
|
|
138
136
|
}
|
|
139
137
|
|
|
140
|
-
var
|
|
138
|
+
var instance;
|
|
139
|
+
var pointer;
|
|
141
140
|
export default function usePointer() {
|
|
142
141
|
if (!pointer) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var add = pointer.add.bind(pointer);
|
|
147
|
-
var remove = pointer.remove.bind(pointer);
|
|
148
|
-
var has = pointer.has.bind(pointer);
|
|
142
|
+
if (!instance) {
|
|
143
|
+
instance = new Pointer();
|
|
144
|
+
}
|
|
149
145
|
|
|
150
|
-
|
|
146
|
+
pointer = {
|
|
147
|
+
add: instance.add.bind(instance),
|
|
148
|
+
remove: instance.remove.bind(instance),
|
|
149
|
+
has: instance.has.bind(instance),
|
|
150
|
+
props: instance.updateProps.bind(instance)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
151
153
|
|
|
152
|
-
return
|
|
153
|
-
add,
|
|
154
|
-
remove,
|
|
155
|
-
has,
|
|
156
|
-
props
|
|
157
|
-
};
|
|
154
|
+
return pointer;
|
|
158
155
|
}
|
package/services/raf.d.ts
CHANGED
|
@@ -9,20 +9,10 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @return {
|
|
12
|
+
* @return {RafService}
|
|
13
13
|
*/
|
|
14
|
-
export default function useRaf():
|
|
15
|
-
export type
|
|
14
|
+
export default function useRaf(): RafService;
|
|
15
|
+
export type RafService = import('./index').ServiceInterface<RafServiceProps>;
|
|
16
16
|
export type RafServiceProps = {
|
|
17
17
|
time: DOMHighResTimeStamp;
|
|
18
18
|
};
|
|
19
|
-
export type RafService = {
|
|
20
|
-
/**
|
|
21
|
-
* Add a function to the resize service. The key must be uniq.
|
|
22
|
-
*/
|
|
23
|
-
add: (key: string, callback: (props: RafServiceProps) => void) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Get the current values of the resize service props.
|
|
26
|
-
*/
|
|
27
|
-
props: () => RafServiceProps;
|
|
28
|
-
};
|
package/services/raf.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getRaf, getCancelRaf } from '../utils/nextFrame.js';
|
|
|
4
4
|
|
|
5
5
|
class Raf extends Service {
|
|
6
6
|
constructor() {
|
|
7
|
-
super();
|
|
7
|
+
super(...arguments);
|
|
8
8
|
|
|
9
9
|
_defineProperty(this, "isTicking", false);
|
|
10
10
|
|
|
@@ -14,57 +14,54 @@ class Raf extends Service {
|
|
|
14
14
|
|
|
15
15
|
_defineProperty(this, "cancelRaf", getCancelRaf());
|
|
16
16
|
|
|
17
|
-
this
|
|
17
|
+
_defineProperty(this, "props", {
|
|
18
|
+
time: performance.now()
|
|
19
|
+
});
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
init() {
|
|
21
23
|
this.isTicking = true;
|
|
22
24
|
this.loop();
|
|
23
|
-
return this;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
loop() {
|
|
28
|
+
this.updateProps();
|
|
27
29
|
this.trigger(this.props);
|
|
28
30
|
|
|
29
31
|
if (!this.isTicking) {
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
this.id = this.raf(this.loop);
|
|
35
|
+
this.id = this.raf(() => this.loop());
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
kill() {
|
|
37
39
|
this.cancelRaf(this.id);
|
|
38
40
|
this.isTicking = false;
|
|
39
|
-
return this;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
43
|
+
updateProps() {
|
|
44
|
+
this.props.time = window.performance.now();
|
|
45
|
+
return this.props;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
var instance
|
|
50
|
+
var instance;
|
|
51
|
+
var raf;
|
|
51
52
|
export default function useRaf() {
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var add = instance.add.bind(instance);
|
|
57
|
-
var remove = instance.remove.bind(instance);
|
|
58
|
-
var has = instance.has.bind(instance);
|
|
53
|
+
if (!raf) {
|
|
54
|
+
if (!instance) {
|
|
55
|
+
instance = new Raf();
|
|
56
|
+
}
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
raf = {
|
|
59
|
+
add: instance.add.bind(instance),
|
|
60
|
+
remove: instance.remove.bind(instance),
|
|
61
|
+
has: instance.has.bind(instance),
|
|
62
|
+
props: instance.updateProps.bind(instance)
|
|
63
|
+
};
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
return
|
|
65
|
-
add,
|
|
66
|
-
remove,
|
|
67
|
-
has,
|
|
68
|
-
props
|
|
69
|
-
};
|
|
66
|
+
return raf;
|
|
70
67
|
}
|
package/services/resize.d.ts
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* remove(key);
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
|
-
* @return {
|
|
11
|
+
* @return {ResizeService}
|
|
12
12
|
*/
|
|
13
|
-
export default function useResize():
|
|
14
|
-
export type
|
|
13
|
+
export default function useResize(): ResizeService;
|
|
14
|
+
export type ResizeService = import('./index').ServiceInterface<ResizeServiceProps>;
|
|
15
15
|
export type ResizeServiceProps = {
|
|
16
16
|
width: number;
|
|
17
17
|
height: number;
|
|
@@ -20,13 +20,3 @@ export type ResizeServiceProps = {
|
|
|
20
20
|
breakpoint?: string;
|
|
21
21
|
breakpoints?: string[];
|
|
22
22
|
};
|
|
23
|
-
export type ResizeService = {
|
|
24
|
-
/**
|
|
25
|
-
* Add a function to the resize service. The key must be uniq.
|
|
26
|
-
*/
|
|
27
|
-
add: (key: string, callback: (props: ResizeServiceProps) => void) => void;
|
|
28
|
-
/**
|
|
29
|
-
* Get the current values of the resize service props.
|
|
30
|
-
*/
|
|
31
|
-
props: () => ResizeServiceProps;
|
|
32
|
-
};
|
package/services/resize.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import Service from './Service.js';
|
|
2
3
|
import debounce from '../utils/debounce.js';
|
|
3
4
|
|
|
4
5
|
class Resize extends Service {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
|
|
9
|
+
_defineProperty(this, "props", {
|
|
10
|
+
width: window.innerWidth,
|
|
11
|
+
height: window.innerHeight,
|
|
12
|
+
ratio: window.innerWidth / window.innerHeight,
|
|
13
|
+
orientation: 'square'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "handler", void 0);
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
init() {
|
|
6
20
|
this.handler = debounce(() => {
|
|
21
|
+
this.updateProps();
|
|
7
22
|
this.trigger(this.props);
|
|
8
23
|
}).bind(this);
|
|
9
24
|
window.addEventListener('resize', this.handler);
|
|
@@ -12,35 +27,35 @@ class Resize extends Service {
|
|
|
12
27
|
|
|
13
28
|
kill() {
|
|
14
29
|
window.removeEventListener('resize', this.handler);
|
|
15
|
-
return this;
|
|
16
30
|
}
|
|
17
31
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
orientation: 'square'
|
|
24
|
-
};
|
|
32
|
+
updateProps() {
|
|
33
|
+
this.props.width = window.innerWidth;
|
|
34
|
+
this.props.height = window.innerHeight;
|
|
35
|
+
this.props.ratio = window.innerWidth / window.innerHeight;
|
|
36
|
+
this.props.orientation = 'square';
|
|
25
37
|
|
|
26
|
-
if (props.ratio > 1) {
|
|
27
|
-
props.orientation = 'landscape';
|
|
38
|
+
if (this.props.ratio > 1) {
|
|
39
|
+
this.props.orientation = 'landscape';
|
|
28
40
|
}
|
|
29
41
|
|
|
30
|
-
if (props.ratio < 1) {
|
|
31
|
-
props.orientation = 'portrait';
|
|
42
|
+
if (this.props.ratio < 1) {
|
|
43
|
+
this.props.orientation = 'portrait';
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
if (this.breakpointElement) {
|
|
35
|
-
props.breakpoint = this.breakpoint;
|
|
36
|
-
props.breakpoints = this.breakpoints;
|
|
47
|
+
this.props.breakpoint = this.breakpoint;
|
|
48
|
+
this.props.breakpoints = this.breakpoints;
|
|
49
|
+
} else {
|
|
50
|
+
this.props.breakpoint = undefined;
|
|
51
|
+
this.props.breakpoints = undefined;
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
return props;
|
|
54
|
+
return this.props;
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
get breakpointElement() {
|
|
43
|
-
return document.querySelector('[data-breakpoint]')
|
|
58
|
+
return document.querySelector('[data-breakpoint]');
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
get breakpoint() {
|
|
@@ -54,22 +69,25 @@ class Resize extends Service {
|
|
|
54
69
|
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
var
|
|
72
|
+
var instance;
|
|
73
|
+
var resize;
|
|
58
74
|
export default function useResize() {
|
|
59
75
|
if (!resize) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var add = resize.add.bind(resize);
|
|
64
|
-
var remove = resize.remove.bind(resize);
|
|
65
|
-
var has = resize.has.bind(resize);
|
|
76
|
+
if (!instance) {
|
|
77
|
+
instance = new Resize();
|
|
78
|
+
}
|
|
66
79
|
|
|
67
|
-
|
|
80
|
+
var add = instance.add.bind(instance);
|
|
81
|
+
var remove = instance.remove.bind(instance);
|
|
82
|
+
var has = instance.has.bind(instance);
|
|
83
|
+
var props = instance.updateProps.bind(instance);
|
|
84
|
+
resize = {
|
|
85
|
+
add,
|
|
86
|
+
remove,
|
|
87
|
+
has,
|
|
88
|
+
props
|
|
89
|
+
};
|
|
90
|
+
}
|
|
68
91
|
|
|
69
|
-
return
|
|
70
|
-
add,
|
|
71
|
-
remove,
|
|
72
|
-
has,
|
|
73
|
-
props
|
|
74
|
-
};
|
|
92
|
+
return resize;
|
|
75
93
|
}
|
package/services/scroll.d.ts
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @return {
|
|
12
|
+
* @return {ScrollService}
|
|
13
13
|
*/
|
|
14
|
-
export default function useScroll():
|
|
15
|
-
export type
|
|
14
|
+
export default function useScroll(): ScrollService;
|
|
15
|
+
export type ScrollService = import('./index').ServiceInterface<ScrollServiceProps>;
|
|
16
16
|
export type ScrollServiceProps = {
|
|
17
17
|
x: number;
|
|
18
18
|
y: number;
|
|
@@ -41,13 +41,3 @@ export type ScrollServiceProps = {
|
|
|
41
41
|
y: 'UP' | 'DOWN' | 'NONE';
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
export type ScrollService = {
|
|
45
|
-
/**
|
|
46
|
-
* Add a function to the resize service. The key must be uniq.
|
|
47
|
-
*/
|
|
48
|
-
add: (key: string, callback: (props: ScrollServiceProps) => void) => void;
|
|
49
|
-
/**
|
|
50
|
-
* Get the current values of the resize service props.
|
|
51
|
-
*/
|
|
52
|
-
props: () => ScrollServiceProps;
|
|
53
|
-
};
|
package/services/scroll.js
CHANGED
|
@@ -6,16 +6,38 @@ class Scroll extends Service {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
|
|
9
|
-
_defineProperty(this, "
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
_defineProperty(this, "props", {
|
|
10
|
+
x: window.pageXOffset,
|
|
11
|
+
y: window.pageYOffset,
|
|
12
|
+
changed: {
|
|
13
|
+
x: false,
|
|
14
|
+
y: false
|
|
15
|
+
},
|
|
16
|
+
last: {
|
|
17
|
+
x: window.pageXOffset,
|
|
18
|
+
y: window.pageYOffset
|
|
19
|
+
},
|
|
20
|
+
delta: {
|
|
21
|
+
x: 0,
|
|
22
|
+
y: 0
|
|
23
|
+
},
|
|
24
|
+
max: {
|
|
25
|
+
x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
|
|
26
|
+
y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
|
|
27
|
+
},
|
|
28
|
+
progress: {
|
|
29
|
+
x: 0,
|
|
30
|
+
y: 0
|
|
31
|
+
},
|
|
32
|
+
direction: {
|
|
33
|
+
x: 'NONE',
|
|
34
|
+
y: 'NONE'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
16
37
|
}
|
|
17
38
|
|
|
18
39
|
init() {
|
|
40
|
+
this.updateProps();
|
|
19
41
|
document.addEventListener('scroll', this, {
|
|
20
42
|
passive: true,
|
|
21
43
|
capture: true
|
|
@@ -25,8 +47,9 @@ class Scroll extends Service {
|
|
|
25
47
|
|
|
26
48
|
get debouncedHandler() {
|
|
27
49
|
var debounced = debounce(() => {
|
|
50
|
+
this.updateProps();
|
|
28
51
|
this.trigger(this.props);
|
|
29
|
-
},
|
|
52
|
+
}, 100);
|
|
30
53
|
Object.defineProperty(this, 'debouncedHandler', {
|
|
31
54
|
value: debounced
|
|
32
55
|
});
|
|
@@ -34,6 +57,7 @@ class Scroll extends Service {
|
|
|
34
57
|
}
|
|
35
58
|
|
|
36
59
|
handleEvent() {
|
|
60
|
+
this.updateProps();
|
|
37
61
|
this.trigger(this.props);
|
|
38
62
|
this.debouncedHandler();
|
|
39
63
|
}
|
|
@@ -43,70 +67,50 @@ class Scroll extends Service {
|
|
|
43
67
|
return this;
|
|
44
68
|
}
|
|
45
69
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
updateProps() {
|
|
71
|
+
var yLast = this.props.y;
|
|
72
|
+
var xLast = this.props.x;
|
|
49
73
|
|
|
50
|
-
if (window.pageYOffset !== this.y) {
|
|
51
|
-
this.y = window.pageYOffset;
|
|
74
|
+
if (window.pageYOffset !== this.props.y) {
|
|
75
|
+
this.props.y = window.pageYOffset;
|
|
52
76
|
}
|
|
53
77
|
|
|
54
|
-
if (window.pageXOffset !== this.x) {
|
|
55
|
-
this.x = window.pageXOffset;
|
|
78
|
+
if (window.pageXOffset !== this.props.x) {
|
|
79
|
+
this.props.x = window.pageXOffset;
|
|
56
80
|
}
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
y: this.y - this.yLast
|
|
72
|
-
},
|
|
73
|
-
progress: {
|
|
74
|
-
x: this.max.x === 0 ? 1 : this.x / this.max.x,
|
|
75
|
-
y: this.max.y === 0 ? 1 : this.y / this.max.y
|
|
76
|
-
},
|
|
77
|
-
direction: {
|
|
78
|
-
x: this.x > this.xLast ? 'RIGHT' : this.x < this.xLast ? 'LEFT' : 'NONE',
|
|
79
|
-
y: this.y > this.yLast ? 'DOWN' : this.y < this.yLast ? 'UP' : 'NONE'
|
|
80
|
-
},
|
|
81
|
-
max: this.max
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get max() {
|
|
86
|
-
return {
|
|
87
|
-
x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
|
|
88
|
-
y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
|
|
89
|
-
};
|
|
82
|
+
this.props.changed.x = this.props.x !== xLast;
|
|
83
|
+
this.props.changed.y = this.props.y !== yLast;
|
|
84
|
+
this.props.last.x = xLast;
|
|
85
|
+
this.props.last.y = yLast;
|
|
86
|
+
this.props.delta.x = this.props.x - xLast;
|
|
87
|
+
this.props.delta.y = this.props.y - yLast;
|
|
88
|
+
this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
|
|
89
|
+
this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
|
|
90
|
+
this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
|
|
91
|
+
this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
|
|
92
|
+
this.props.direction.x = this.props.x > xLast ? 'RIGHT' : this.props.x < xLast ? 'LEFT' : 'NONE';
|
|
93
|
+
this.props.direction.y = this.props.y > yLast ? 'DOWN' : this.props.y < yLast ? 'UP' : 'NONE';
|
|
94
|
+
return this.props;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
var
|
|
99
|
+
var instance;
|
|
100
|
+
var scroll;
|
|
95
101
|
export default function useScroll() {
|
|
96
102
|
if (!scroll) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var add = scroll.add.bind(scroll);
|
|
101
|
-
var remove = scroll.remove.bind(scroll);
|
|
102
|
-
var has = scroll.has.bind(scroll);
|
|
103
|
+
if (!instance) {
|
|
104
|
+
instance = new Scroll();
|
|
105
|
+
}
|
|
103
106
|
|
|
104
|
-
|
|
107
|
+
scroll = {
|
|
108
|
+
add: instance.add.bind(instance),
|
|
109
|
+
remove: instance.remove.bind(instance),
|
|
110
|
+
has: instance.has.bind(instance),
|
|
111
|
+
props: instance.updateProps.bind(instance)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
105
114
|
|
|
106
|
-
return
|
|
107
|
-
add,
|
|
108
|
-
remove,
|
|
109
|
-
has,
|
|
110
|
-
props
|
|
111
|
-
};
|
|
115
|
+
return scroll;
|
|
112
116
|
}
|
package/utils/collide/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { collidePointRect, collideRectRect, boundingRectToCircle, collideCircleRect, collideCircleCircle, collidePointCircle };
|
|
1
|
+
export { default as boundingRectToCircle } from "./boundingRectToCircle.js";
|
|
2
|
+
export { default as collideCircleCircle } from "./collideCircleCircle.js";
|
|
3
|
+
export { default as collideCircleRect } from "./collideCircleRect.js";
|
|
4
|
+
export { default as collidePointCircle } from "./collidePointCircle.js";
|
|
5
|
+
export { default as collidePointRect } from "./collidePointRect.js";
|
|
6
|
+
export { default as collideRectRect } from "./collideRectRect.js";
|
package/utils/collide/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { collidePointRect, collideRectRect, boundingRectToCircle, collideCircleRect, collideCircleCircle, collidePointCircle };
|
|
1
|
+
export { default as boundingRectToCircle } from './boundingRectToCircle.js';
|
|
2
|
+
export { default as collideCircleCircle } from './collideCircleCircle.js';
|
|
3
|
+
export { default as collideCircleRect } from './collideCircleRect.js';
|
|
4
|
+
export { default as collidePointCircle } from './collidePointCircle.js';
|
|
5
|
+
export { default as collidePointRect } from './collidePointRect.js';
|
|
6
|
+
export { default as collideRectRect } from './collideRectRect.js';
|
package/utils/css/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { classes, styles, matrix, transition };
|
|
1
|
+
export * as classes from "./classes.js";
|
|
2
|
+
export * as styles from "./styles.js";
|
|
3
|
+
export { default as matrix } from "./matrix.js";
|
|
4
|
+
export { default as transition } from "./transition.js";
|
package/utils/css/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export {
|
|
1
|
+
import * as _classes from './classes.js';
|
|
2
|
+
export { _classes as classes };
|
|
3
|
+
import * as _styles from './styles.js';
|
|
4
|
+
export { _styles as styles };
|
|
5
|
+
export { default as matrix } from './matrix.js';
|
|
6
|
+
export { default as transition } from './transition.js';
|