@studiometa/js-toolkit 2.0.0-beta.5 → 2.0.0-beta.9
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 +27 -1
- package/Base/index.js +98 -42
- package/Base/managers/EventsManager.d.ts +3 -1
- package/Base/managers/EventsManager.js +6 -2
- package/Base/managers/OptionsManager.d.ts +2 -0
- package/Base/managers/RefsManager.d.ts +2 -0
- package/Base/managers/RefsManager.js +5 -0
- package/Base/managers/ServicesManager.d.ts +29 -4
- package/Base/managers/ServicesManager.js +6 -2
- package/README.md +13 -70
- package/decorators/index.d.ts +8 -9
- package/decorators/index.js +8 -9
- package/decorators/withBreakpointObserver.js +2 -2
- package/decorators/withDrag.js +8 -2
- package/decorators/withIntersectionObserver.js +4 -3
- package/decorators/withMountWhenInView.js +7 -4
- package/decorators/withScrolledInView.d.ts +4 -1
- package/decorators/withScrolledInView.js +56 -39
- package/decorators/withVue2.js +2 -2
- package/helpers/index.d.ts +4 -5
- package/helpers/index.js +4 -5
- package/index.d.ts +4 -21
- 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 +4 -18
- package/services/drag.js +81 -104
- 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.js +2 -2
- package/utils/index.d.ts +11 -35
- package/utils/index.js +11 -17
- package/utils/math/ease.d.ts +78 -0
- package/utils/math/ease.js +41 -0
- package/utils/math/index.d.ts +8 -8
- package/utils/math/index.js +8 -8
- package/utils/object/getAllProperties.js +1 -1
- package/utils/object/index.d.ts +3 -4
- package/utils/object/index.js +3 -4
- package/utils/string/index.d.ts +10 -11
- package/utils/string/index.js +10 -11
package/services/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { useKey, usePointer, useDrag, useLoad, useRaf, useResize, useScroll };
|
|
1
|
+
export { default as useDrag } from './drag.js';
|
|
2
|
+
export { default as useKey } from './key.js';
|
|
3
|
+
export { default as useLoad } from './load.js';
|
|
4
|
+
export { default as usePointer } from './pointer.js';
|
|
5
|
+
export { default as useRaf } from './raf.js';
|
|
6
|
+
export { default as useResize } from './resize.js';
|
|
7
|
+
export { default as useScroll } from './scroll.js';
|
package/services/key.d.ts
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @return {
|
|
12
|
+
* @return {KeyService}
|
|
13
13
|
*/
|
|
14
|
-
export default function useKey():
|
|
15
|
-
export type
|
|
14
|
+
export default function useKey(): KeyService;
|
|
15
|
+
export type KeyService = import('./index').ServiceInterface<KeyServiceProps>;
|
|
16
16
|
export type KeyServiceProps = {
|
|
17
17
|
event: KeyboardEvent;
|
|
18
18
|
triggered: number;
|
|
19
|
+
direction: 'up' | 'down' | 'none';
|
|
19
20
|
isUp: boolean;
|
|
20
21
|
isDown: boolean;
|
|
21
22
|
ENTER: boolean;
|
|
@@ -27,13 +28,3 @@ export type KeyServiceProps = {
|
|
|
27
28
|
RIGHT: boolean;
|
|
28
29
|
DOWN: boolean;
|
|
29
30
|
};
|
|
30
|
-
export type KeyService = {
|
|
31
|
-
/**
|
|
32
|
-
* Add a function to the resize service. The key must be uniq.
|
|
33
|
-
*/
|
|
34
|
-
add: (key: string, callback: (props: KeyServiceProps) => void) => void;
|
|
35
|
-
/**
|
|
36
|
-
* Get the current values of the resize service props.
|
|
37
|
-
*/
|
|
38
|
-
props: () => KeyServiceProps;
|
|
39
|
-
};
|
package/services/key.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
2
|
import Service from './Service.js';
|
|
8
3
|
import keyCodes from '../utils/keyCodes.js';
|
|
9
4
|
|
|
@@ -11,79 +6,83 @@ class Key extends Service {
|
|
|
11
6
|
constructor() {
|
|
12
7
|
super(...arguments);
|
|
13
8
|
|
|
14
|
-
_defineProperty(this, "
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
_defineProperty(this, "previousEvent", void 0);
|
|
10
|
+
|
|
11
|
+
_defineProperty(this, "props", {
|
|
12
|
+
event: null,
|
|
13
|
+
triggered: 0,
|
|
14
|
+
isUp: false,
|
|
15
|
+
isDown: false,
|
|
16
|
+
ENTER: false,
|
|
17
|
+
SPACE: false,
|
|
18
|
+
TAB: false,
|
|
19
|
+
ESC: false,
|
|
20
|
+
LEFT: false,
|
|
21
|
+
UP: false,
|
|
22
|
+
RIGHT: false,
|
|
23
|
+
DOWN: false,
|
|
24
|
+
direction: 'none'
|
|
25
|
+
});
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
init() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
29
|
+
document.addEventListener('keydown', this);
|
|
30
|
+
document.addEventListener('keyup', this);
|
|
31
|
+
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
document.addEventListener('keyup', this.handler, {
|
|
31
|
-
passive: false
|
|
32
|
-
});
|
|
33
|
-
return this;
|
|
33
|
+
handleEvent(event) {
|
|
34
|
+
this.updateProps(event);
|
|
35
|
+
this.trigger(this.props);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
kill() {
|
|
37
|
-
document.removeEventListener('keydown', this
|
|
38
|
-
document.removeEventListener('keyup', this
|
|
39
|
-
return this;
|
|
39
|
+
document.removeEventListener('keydown', this);
|
|
40
|
+
document.removeEventListener('keyup', this);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
var
|
|
43
|
+
updateProps(event) {
|
|
44
|
+
var _this$previousEvent;
|
|
45
|
+
|
|
46
|
+
this.props.event = event;
|
|
47
|
+
Object.entries(keyCodes).forEach(_ref => {
|
|
44
48
|
var [name, code] = _ref;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}, {});
|
|
49
|
+
this.props[name] = code === event.keyCode;
|
|
50
|
+
});
|
|
48
51
|
|
|
49
|
-
if (!this.previousEvent
|
|
50
|
-
this.triggered = 0;
|
|
52
|
+
if (!this.previousEvent) {
|
|
53
|
+
this.props.triggered = 0;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
if (this.event.type === 'keydown' && this.previousEvent.type === 'keydown') {
|
|
54
|
-
this.triggered += 1;
|
|
56
|
+
if (this.props.event.type === 'keydown' && ((_this$previousEvent = this.previousEvent) === null || _this$previousEvent === void 0 ? void 0 : _this$previousEvent.type) === 'keydown') {
|
|
57
|
+
this.props.triggered += 1;
|
|
55
58
|
} else {
|
|
56
|
-
this.triggered = 1;
|
|
59
|
+
this.props.triggered = 1;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
this.previousEvent = this.event;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
isUp: this.event.type === 'keyup',
|
|
65
|
-
isDown: this.event.type === 'keydown'
|
|
66
|
-
}, keys);
|
|
62
|
+
this.previousEvent = this.props.event;
|
|
63
|
+
this.props.direction = this.props.event.type === 'keydown' ? 'down' : 'up';
|
|
64
|
+
this.props.isUp = this.props.event.type === 'keyup';
|
|
65
|
+
this.props.isDown = this.props.event.type === 'keydown';
|
|
66
|
+
return this.props;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
var
|
|
71
|
+
var instance;
|
|
72
|
+
var key;
|
|
72
73
|
export default function useKey() {
|
|
73
74
|
if (!key) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var add = key.add.bind(key);
|
|
78
|
-
var remove = key.remove.bind(key);
|
|
79
|
-
var has = key.has.bind(key);
|
|
75
|
+
if (!instance) {
|
|
76
|
+
instance = new Key();
|
|
77
|
+
}
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
key = {
|
|
80
|
+
add: instance.add.bind(instance),
|
|
81
|
+
remove: instance.remove.bind(instance),
|
|
82
|
+
has: instance.has.bind(instance),
|
|
83
|
+
props: instance.updateProps.bind(instance)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
82
86
|
|
|
83
|
-
return
|
|
84
|
-
add,
|
|
85
|
-
remove,
|
|
86
|
-
has,
|
|
87
|
-
props
|
|
88
|
-
};
|
|
87
|
+
return key;
|
|
89
88
|
}
|
package/services/load.d.ts
CHANGED
|
@@ -9,20 +9,10 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @return {
|
|
12
|
+
* @return {LoadService}
|
|
13
13
|
*/
|
|
14
|
-
export default function useLoad():
|
|
15
|
-
export type
|
|
14
|
+
export default function useLoad(): LoadService;
|
|
15
|
+
export type LoadService = import('./index').ServiceInterface<LoadServiceProps>;
|
|
16
16
|
export type LoadServiceProps = {
|
|
17
17
|
time: DOMHighResTimeStamp;
|
|
18
18
|
};
|
|
19
|
-
export type LoadService = {
|
|
20
|
-
/**
|
|
21
|
-
* Add a function to the resize service. The key must be uniq.
|
|
22
|
-
*/
|
|
23
|
-
add: (key: string, callback: (props: LoadServiceProps) => void) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Get the current values of the resize service props.
|
|
26
|
-
*/
|
|
27
|
-
props: () => LoadServiceProps;
|
|
28
|
-
};
|
package/services/load.js
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import Service from './Service.js';
|
|
2
3
|
|
|
3
4
|
class Load extends Service {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "props", {
|
|
9
|
+
time: window.performance.now()
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
init() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
14
|
+
window.addEventListener('load', this);
|
|
15
|
+
}
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
handleEvent() {
|
|
18
|
+
this.updateProps();
|
|
19
|
+
this.trigger(this.props);
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
kill() {
|
|
14
|
-
window.removeEventListener('load', this
|
|
15
|
-
return this;
|
|
23
|
+
window.removeEventListener('load', this);
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
updateProps() {
|
|
27
|
+
this.props.time = window.performance.now();
|
|
28
|
+
return this.props;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
var instance
|
|
33
|
+
var instance;
|
|
34
|
+
var load;
|
|
25
35
|
export default function useLoad() {
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (!load) {
|
|
37
|
+
if (!instance) {
|
|
38
|
+
instance = new Load();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
load = {
|
|
42
|
+
add: instance.add.bind(instance),
|
|
43
|
+
remove: instance.remove.bind(instance),
|
|
44
|
+
has: instance.has.bind(instance),
|
|
45
|
+
props: instance.updateProps.bind(instance)
|
|
46
|
+
};
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
return
|
|
39
|
-
add,
|
|
40
|
-
remove,
|
|
41
|
-
has,
|
|
42
|
-
props
|
|
43
|
-
};
|
|
49
|
+
return load;
|
|
44
50
|
}
|
package/services/pointer.d.ts
CHANGED
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
* props();
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
12
|
+
* @todo Add element as parameter to get the pointer position relatively from.
|
|
13
|
+
* @return {PointerService}
|
|
13
14
|
*/
|
|
14
|
-
export default function usePointer():
|
|
15
|
-
export type
|
|
15
|
+
export default function usePointer(): PointerService;
|
|
16
|
+
export type PointerService = import('./index').ServiceInterface<PointerServiceProps>;
|
|
16
17
|
export type PointerServiceProps = {
|
|
17
18
|
event: MouseEvent | TouchEvent;
|
|
18
19
|
isDown: boolean;
|
|
@@ -39,13 +40,3 @@ export type PointerServiceProps = {
|
|
|
39
40
|
y: number;
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
|
-
export type PointerService = {
|
|
43
|
-
/**
|
|
44
|
-
* Add a function to the resize service. The key must be uniq.
|
|
45
|
-
*/
|
|
46
|
-
add: (key: string, callback: (props: PointerServiceProps) => void) => void;
|
|
47
|
-
/**
|
|
48
|
-
* Get the current values of the resize service props.
|
|
49
|
-
*/
|
|
50
|
-
props: () => PointerServiceProps;
|
|
51
|
-
};
|
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
|
-
};
|