@studiometa/js-toolkit 2.0.0-alpha.1 → 2.0.0-alpha.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 +29 -47
- package/Base/index.js +144 -171
- package/Base/managers/ChildrenManager.d.ts +6 -6
- package/Base/managers/ChildrenManager.js +95 -119
- package/Base/managers/EventsManager.d.ts +9 -9
- package/Base/managers/EventsManager.js +128 -161
- package/Base/managers/OptionsManager.d.ts +50 -5
- package/Base/managers/OptionsManager.js +115 -116
- package/Base/managers/RefsManager.js +62 -73
- package/Base/managers/ServicesManager.d.ts +14 -3
- package/Base/managers/ServicesManager.js +78 -77
- package/Base/utils.js +5 -8
- package/README.md +12 -70
- package/decorators/index.js +1 -2
- package/decorators/withBreakpointManager.d.ts +4 -4
- package/decorators/withBreakpointManager.js +37 -75
- package/decorators/withBreakpointObserver.d.ts +2 -2
- package/decorators/withBreakpointObserver.js +54 -77
- package/decorators/withDrag.d.ts +3 -3
- package/decorators/withDrag.js +17 -41
- package/decorators/withExtraConfig.d.ts +3 -3
- package/decorators/withExtraConfig.js +2 -24
- package/decorators/withIntersectionObserver.d.ts +2 -2
- package/decorators/withIntersectionObserver.js +17 -56
- package/decorators/withMountWhenInView.d.ts +3 -3
- package/decorators/withMountWhenInView.js +23 -51
- package/helpers/createApp.d.ts +3 -3
- package/helpers/createApp.js +10 -12
- package/helpers/importOnInteraction.d.ts +3 -3
- package/helpers/importOnInteraction.js +7 -8
- package/helpers/importWhenIdle.d.ts +3 -3
- package/helpers/importWhenIdle.js +7 -8
- package/helpers/importWhenVisible.d.ts +3 -3
- package/helpers/importWhenVisible.js +9 -16
- package/helpers/index.d.ts +1 -3
- package/helpers/index.js +1 -4
- package/helpers/utils.js +1 -2
- package/index.d.ts +14 -4
- package/index.js +4 -4
- package/index.modern.js +1 -2
- package/index.umd.js +1 -2
- package/package.json +4 -6
- package/services/Service.js +48 -67
- package/services/drag.js +143 -179
- package/services/index.js +1 -2
- package/services/key.js +55 -97
- package/services/load.d.ts +1 -1
- package/services/load.js +21 -50
- package/services/pointer.js +117 -156
- package/services/raf.js +36 -64
- package/services/resize.js +47 -86
- package/services/scroll.js +81 -120
- package/utils/collide/boundingRectToCircle.js +7 -6
- package/utils/collide/collideCircleCircle.js +1 -2
- package/utils/collide/collideCircleRect.js +1 -2
- package/utils/collide/collidePointCircle.js +1 -2
- package/utils/collide/collidePointRect.js +1 -2
- package/utils/collide/collideRectRect.js +1 -2
- package/utils/collide/index.js +1 -2
- package/utils/css/classes.js +2 -3
- package/utils/css/index.js +1 -2
- package/utils/css/matrix.js +1 -2
- package/utils/css/styles.js +3 -8
- package/utils/css/transition.js +67 -140
- package/utils/debounce.js +3 -4
- package/utils/focusTrap.js +4 -5
- package/utils/history.js +13 -20
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -2
- package/utils/keyCodes.js +1 -2
- package/utils/math/clamp.js +1 -2
- package/utils/math/clamp01.js +1 -2
- package/utils/math/damp.js +1 -2
- package/utils/math/index.js +1 -2
- package/utils/math/inertiaFinalValue.js +1 -2
- package/utils/math/lerp.js +1 -2
- package/utils/math/map.js +1 -2
- package/utils/math/round.js +1 -2
- package/utils/memoize.d.ts +30 -0
- package/utils/memoize.js +30 -0
- package/utils/nextFrame.js +4 -9
- package/utils/object/autoBind.js +11 -19
- package/utils/object/getAllProperties.js +3 -11
- package/utils/object/index.js +1 -2
- package/utils/object/isObject.js +2 -4
- package/utils/string/index.js +1 -2
- package/utils/string/withLeadingCharacters.js +1 -2
- package/utils/string/withLeadingSlash.js +1 -2
- package/utils/string/withTrailingCharacters.js +1 -2
- package/utils/string/withTrailingSlash.js +1 -2
- package/utils/string/withoutLeadingCharacters.js +1 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +1 -2
- package/utils/string/withoutLeadingSlash.js +1 -2
- package/utils/string/withoutTrailingCharacters.js +1 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +1 -2
- package/utils/string/withoutTrailingSlash.js +1 -2
- package/utils/throttle.js +2 -3
- package/Base/index.js.map +0 -1
- package/Base/managers/ChildrenManager.js.map +0 -1
- package/Base/managers/EventsManager.js.map +0 -1
- package/Base/managers/OptionsManager.js.map +0 -1
- package/Base/managers/RefsManager.js.map +0 -1
- package/Base/managers/ServicesManager.js.map +0 -1
- package/Base/utils.js.map +0 -1
- package/components/Accordion/Accordion.d.ts +0 -83
- package/components/Accordion/Accordion.js +0 -121
- package/components/Accordion/Accordion.js.map +0 -1
- package/components/Accordion/AccordionItem.d.ts +0 -122
- package/components/Accordion/AccordionItem.js +0 -327
- package/components/Accordion/AccordionItem.js.map +0 -1
- package/components/Accordion/index.d.ts +0 -27
- package/components/Accordion/index.js +0 -39
- package/components/Accordion/index.js.map +0 -1
- package/components/Cursor.d.ts +0 -138
- package/components/Cursor.js +0 -167
- package/components/Cursor.js.map +0 -1
- package/components/Draggable.d.ts +0 -49
- package/components/Draggable.js +0 -77
- package/components/Draggable.js.map +0 -1
- package/components/Modal.d.ts +0 -158
- package/components/Modal.js +0 -270
- package/components/Modal.js.map +0 -1
- package/components/Tabs.d.ts +0 -108
- package/components/Tabs.js +0 -195
- package/components/Tabs.js.map +0 -1
- package/components/index.d.ts +0 -6
- package/components/index.js +0 -7
- package/components/index.js.map +0 -1
- package/decorators/index.js.map +0 -1
- package/decorators/withBreakpointManager.js.map +0 -1
- package/decorators/withBreakpointObserver.js.map +0 -1
- package/decorators/withDrag.js.map +0 -1
- package/decorators/withExtraConfig.js.map +0 -1
- package/decorators/withIntersectionObserver.js.map +0 -1
- package/decorators/withMountWhenInView.js.map +0 -1
- package/helpers/createApp.js.map +0 -1
- package/helpers/createBase.d.ts +0 -7
- package/helpers/createBase.js +0 -7
- package/helpers/createBase.js.map +0 -1
- package/helpers/defineComponent.d.ts +0 -11
- package/helpers/defineComponent.js +0 -68
- package/helpers/defineComponent.js.map +0 -1
- package/helpers/importOnInteraction.js.map +0 -1
- package/helpers/importWhenIdle.js.map +0 -1
- package/helpers/importWhenVisible.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/helpers/utils.js.map +0 -1
- package/index.js.map +0 -1
- package/index.modern.js.map +0 -1
- package/index.umd.js.map +0 -1
- package/services/Service.js.map +0 -1
- package/services/drag.js.map +0 -1
- package/services/index.js.map +0 -1
- package/services/key.js.map +0 -1
- package/services/load.js.map +0 -1
- package/services/pointer.js.map +0 -1
- package/services/raf.js.map +0 -1
- package/services/resize.js.map +0 -1
- package/services/scroll.js.map +0 -1
- package/utils/collide/boundingRectToCircle.js.map +0 -1
- package/utils/collide/collideCircleCircle.js.map +0 -1
- package/utils/collide/collideCircleRect.js.map +0 -1
- package/utils/collide/collidePointCircle.js.map +0 -1
- package/utils/collide/collidePointRect.js.map +0 -1
- package/utils/collide/collideRectRect.js.map +0 -1
- package/utils/collide/index.js.map +0 -1
- package/utils/css/classes.js.map +0 -1
- package/utils/css/index.js.map +0 -1
- package/utils/css/matrix.js.map +0 -1
- package/utils/css/styles.js.map +0 -1
- package/utils/css/transition.js.map +0 -1
- package/utils/debounce.js.map +0 -1
- package/utils/focusTrap.js.map +0 -1
- package/utils/history.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/keyCodes.js.map +0 -1
- package/utils/math/clamp.js.map +0 -1
- package/utils/math/clamp01.js.map +0 -1
- package/utils/math/damp.js.map +0 -1
- package/utils/math/index.js.map +0 -1
- package/utils/math/inertiaFinalValue.js.map +0 -1
- package/utils/math/lerp.js.map +0 -1
- package/utils/math/map.js.map +0 -1
- package/utils/math/round.js.map +0 -1
- package/utils/nextFrame.js.map +0 -1
- package/utils/object/autoBind.js.map +0 -1
- package/utils/object/getAllProperties.js.map +0 -1
- package/utils/object/index.js.map +0 -1
- package/utils/object/isObject.js.map +0 -1
- package/utils/string/index.js.map +0 -1
- package/utils/string/withLeadingCharacters.js.map +0 -1
- package/utils/string/withLeadingSlash.js.map +0 -1
- package/utils/string/withTrailingCharacters.js.map +0 -1
- package/utils/string/withTrailingSlash.js.map +0 -1
- package/utils/string/withoutLeadingCharacters.js.map +0 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutLeadingSlash.js.map +0 -1
- package/utils/string/withoutTrailingCharacters.js.map +0 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutTrailingSlash.js.map +0 -1
- package/utils/throttle.js.map +0 -1
package/services/key.js
CHANGED
|
@@ -1,111 +1,72 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
5
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
2
|
|
|
10
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; }
|
|
11
4
|
|
|
12
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; }
|
|
13
6
|
|
|
14
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
-
|
|
16
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
17
|
-
|
|
18
7
|
import Service from './Service.js';
|
|
19
8
|
import keyCodes from '../utils/keyCodes.js';
|
|
20
9
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var _super = _createSuper(Key);
|
|
25
|
-
|
|
26
|
-
function Key() {
|
|
27
|
-
var _this;
|
|
28
|
-
|
|
29
|
-
_classCallCheck(this, Key);
|
|
30
|
-
|
|
31
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
32
|
-
args[_key] = arguments[_key];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
36
|
-
|
|
37
|
-
_defineProperty(_assertThisInitialized(_this), "event", {});
|
|
10
|
+
class Key extends Service {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
38
13
|
|
|
39
|
-
_defineProperty(
|
|
14
|
+
_defineProperty(this, "event", {});
|
|
40
15
|
|
|
41
|
-
_defineProperty(
|
|
16
|
+
_defineProperty(this, "triggered", 0);
|
|
42
17
|
|
|
43
|
-
|
|
18
|
+
_defineProperty(this, "previousEvent", {});
|
|
44
19
|
}
|
|
45
20
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
21
|
+
init() {
|
|
22
|
+
this.handler = event => {
|
|
23
|
+
this.event = event;
|
|
24
|
+
this.trigger(this.props);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
document.addEventListener('keydown', this.handler, {
|
|
28
|
+
passive: false
|
|
29
|
+
});
|
|
30
|
+
document.addEventListener('keyup', this.handler, {
|
|
31
|
+
passive: false
|
|
32
|
+
});
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
kill() {
|
|
37
|
+
document.removeEventListener('keydown', this.handler);
|
|
38
|
+
document.removeEventListener('keyup', this.handler);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
get props() {
|
|
43
|
+
var keys = Object.entries(keyCodes).reduce((acc, _ref) => {
|
|
44
|
+
var [name, code] = _ref;
|
|
45
|
+
acc[name] = code === this.event.keyCode;
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
document.addEventListener('keyup', this.handler, {
|
|
61
|
-
passive: false
|
|
62
|
-
});
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
key: "kill",
|
|
67
|
-
value: function kill() {
|
|
68
|
-
document.removeEventListener('keydown', this.handler);
|
|
69
|
-
document.removeEventListener('keyup', this.handler);
|
|
70
|
-
return this;
|
|
49
|
+
if (!this.previousEvent.type) {
|
|
50
|
+
this.triggered = 0;
|
|
71
51
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var keys = Object.entries(keyCodes).reduce(function (acc, _ref) {
|
|
78
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
79
|
-
name = _ref2[0],
|
|
80
|
-
code = _ref2[1];
|
|
81
|
-
|
|
82
|
-
acc[name] = code === _this3.event.keyCode;
|
|
83
|
-
return acc;
|
|
84
|
-
}, {});
|
|
85
|
-
|
|
86
|
-
if (!this.previousEvent.type) {
|
|
87
|
-
this.triggered = 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (this.event.type === 'keydown' && this.previousEvent.type === 'keydown') {
|
|
91
|
-
this.triggered += 1;
|
|
92
|
-
} else {
|
|
93
|
-
this.triggered = 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
this.previousEvent = this.event;
|
|
97
|
-
return _objectSpread({
|
|
98
|
-
event: this.event,
|
|
99
|
-
triggered: this.triggered,
|
|
100
|
-
direction: this.event.type === 'keydown' ? 'down' : 'up',
|
|
101
|
-
isUp: this.event.type === 'keyup',
|
|
102
|
-
isDown: this.event.type === 'keydown'
|
|
103
|
-
}, keys);
|
|
52
|
+
|
|
53
|
+
if (this.event.type === 'keydown' && this.previousEvent.type === 'keydown') {
|
|
54
|
+
this.triggered += 1;
|
|
55
|
+
} else {
|
|
56
|
+
this.triggered = 1;
|
|
104
57
|
}
|
|
105
|
-
}]);
|
|
106
58
|
|
|
107
|
-
|
|
108
|
-
|
|
59
|
+
this.previousEvent = this.event;
|
|
60
|
+
return _objectSpread({
|
|
61
|
+
event: this.event,
|
|
62
|
+
triggered: this.triggered,
|
|
63
|
+
direction: this.event.type === 'keydown' ? 'down' : 'up',
|
|
64
|
+
isUp: this.event.type === 'keyup',
|
|
65
|
+
isDown: this.event.type === 'keydown'
|
|
66
|
+
}, keys);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
109
70
|
|
|
110
71
|
var key = null;
|
|
111
72
|
export default function useKey() {
|
|
@@ -117,15 +78,12 @@ export default function useKey() {
|
|
|
117
78
|
var remove = key.remove.bind(key);
|
|
118
79
|
var has = key.has.bind(key);
|
|
119
80
|
|
|
120
|
-
var props =
|
|
121
|
-
return key.props;
|
|
122
|
-
};
|
|
81
|
+
var props = () => key.props;
|
|
123
82
|
|
|
124
83
|
return {
|
|
125
|
-
add
|
|
126
|
-
remove
|
|
127
|
-
has
|
|
128
|
-
props
|
|
84
|
+
add,
|
|
85
|
+
remove,
|
|
86
|
+
has,
|
|
87
|
+
props
|
|
129
88
|
};
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=key.js.map
|
|
89
|
+
}
|
package/services/load.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @return {ServiceInterface & LoadService}
|
|
13
13
|
*/
|
|
14
|
-
export default function
|
|
14
|
+
export default function useLoad(): ServiceInterface & LoadService;
|
|
15
15
|
export type ServiceInterface = import('./index').ServiceInterface;
|
|
16
16
|
export type LoadServiceProps = {
|
|
17
17
|
time: DOMHighResTimeStamp;
|
package/services/load.js
CHANGED
|
@@ -1,56 +1,28 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
|
|
7
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
-
|
|
9
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
-
|
|
11
1
|
import Service from './Service.js';
|
|
12
2
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function Load() {
|
|
19
|
-
_classCallCheck(this, Load);
|
|
3
|
+
class Load extends Service {
|
|
4
|
+
init() {
|
|
5
|
+
this.handler = () => {
|
|
6
|
+
this.trigger(this.props);
|
|
7
|
+
};
|
|
20
8
|
|
|
21
|
-
|
|
9
|
+
window.addEventListener('load', this.handler);
|
|
10
|
+
return this;
|
|
22
11
|
}
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.handler = function () {
|
|
30
|
-
_this.trigger(_this.props);
|
|
31
|
-
};
|
|
13
|
+
kill() {
|
|
14
|
+
window.removeEventListener('load', this.handler);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
32
17
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, {
|
|
37
|
-
key: "kill",
|
|
38
|
-
value: function kill() {
|
|
39
|
-
window.removeEventListener('load', this.handler);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
key: "props",
|
|
44
|
-
get: function get() {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
}]);
|
|
18
|
+
get props() {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
48
21
|
|
|
49
|
-
|
|
50
|
-
}(Service);
|
|
22
|
+
}
|
|
51
23
|
|
|
52
24
|
var instance = null;
|
|
53
|
-
export default function
|
|
25
|
+
export default function useLoad() {
|
|
54
26
|
if (!instance) {
|
|
55
27
|
instance = new Load();
|
|
56
28
|
}
|
|
@@ -64,10 +36,9 @@ export default function useRaf() {
|
|
|
64
36
|
}
|
|
65
37
|
|
|
66
38
|
return {
|
|
67
|
-
add
|
|
68
|
-
remove
|
|
69
|
-
has
|
|
70
|
-
props
|
|
39
|
+
add,
|
|
40
|
+
remove,
|
|
41
|
+
has,
|
|
42
|
+
props
|
|
71
43
|
};
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=load.js.map
|
|
44
|
+
}
|
package/services/pointer.js
CHANGED
|
@@ -1,177 +1,141 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
-
|
|
9
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
-
|
|
11
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
|
-
|
|
13
2
|
import Service from './Service.js';
|
|
14
3
|
|
|
15
4
|
function isTouchEvent(event) {
|
|
16
5
|
return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;
|
|
17
6
|
}
|
|
18
7
|
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
class Pointer extends Service {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
21
11
|
|
|
22
|
-
|
|
12
|
+
_defineProperty(this, "isDown", false);
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
var _this;
|
|
14
|
+
_defineProperty(this, "y", window.innerHeight / 2);
|
|
26
15
|
|
|
27
|
-
|
|
16
|
+
_defineProperty(this, "yLast", window.innerHeight / 2);
|
|
28
17
|
|
|
29
|
-
|
|
30
|
-
args[_key] = arguments[_key];
|
|
31
|
-
}
|
|
18
|
+
_defineProperty(this, "x", window.innerWidth / 2);
|
|
32
19
|
|
|
33
|
-
|
|
20
|
+
_defineProperty(this, "xLast", window.innerWidth / 2);
|
|
34
21
|
|
|
35
|
-
_defineProperty(
|
|
22
|
+
_defineProperty(this, "event", void 0);
|
|
36
23
|
|
|
37
|
-
_defineProperty(
|
|
24
|
+
_defineProperty(this, "hasRaf", false);
|
|
25
|
+
}
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
init() {
|
|
28
|
+
document.documentElement.addEventListener('mouseenter', this, {
|
|
29
|
+
once: true,
|
|
30
|
+
capture: true
|
|
31
|
+
});
|
|
32
|
+
var options = {
|
|
33
|
+
passive: true,
|
|
34
|
+
capture: true
|
|
35
|
+
};
|
|
36
|
+
document.addEventListener('mousemove', this, options);
|
|
37
|
+
document.addEventListener('touchmove', this, options);
|
|
38
|
+
document.addEventListener('mousedown', this, options);
|
|
39
|
+
document.addEventListener('touchstart', this, options);
|
|
40
|
+
document.addEventListener('mouseup', this, options);
|
|
41
|
+
document.addEventListener('touchend', this, options);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
handleEvent(event) {
|
|
46
|
+
switch (event.type) {
|
|
47
|
+
case 'mouseenter':
|
|
48
|
+
case 'mousemove':
|
|
49
|
+
case 'touchmove':
|
|
50
|
+
this.handler(event);
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case 'mousedown':
|
|
54
|
+
case 'touchstart':
|
|
55
|
+
this.downHandler();
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'mouseup':
|
|
59
|
+
case 'touchend':
|
|
60
|
+
this.upHandler();
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
42
64
|
|
|
43
|
-
|
|
65
|
+
kill() {
|
|
66
|
+
document.removeEventListener('mousemove', this);
|
|
67
|
+
document.removeEventListener('touchmove', this);
|
|
68
|
+
document.removeEventListener('mousedown', this);
|
|
69
|
+
document.removeEventListener('touchstart', this);
|
|
70
|
+
document.removeEventListener('mouseup', this);
|
|
71
|
+
document.removeEventListener('touchend', this);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
44
74
|
|
|
45
|
-
|
|
75
|
+
handler(event) {
|
|
76
|
+
this.updateValues(event);
|
|
77
|
+
this.trigger(this.props);
|
|
78
|
+
}
|
|
46
79
|
|
|
47
|
-
|
|
80
|
+
downHandler() {
|
|
81
|
+
this.isDown = true;
|
|
82
|
+
this.trigger(this.props);
|
|
83
|
+
}
|
|
48
84
|
|
|
49
|
-
|
|
85
|
+
upHandler() {
|
|
86
|
+
this.isDown = false;
|
|
87
|
+
this.trigger(this.props);
|
|
50
88
|
}
|
|
51
89
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
value: function init() {
|
|
55
|
-
document.documentElement.addEventListener('mouseenter', this, {
|
|
56
|
-
once: true,
|
|
57
|
-
capture: true
|
|
58
|
-
});
|
|
59
|
-
var options = {
|
|
60
|
-
passive: true,
|
|
61
|
-
capture: true
|
|
62
|
-
};
|
|
63
|
-
document.addEventListener('mousemove', this, options);
|
|
64
|
-
document.addEventListener('touchmove', this, options);
|
|
65
|
-
document.addEventListener('mousedown', this, options);
|
|
66
|
-
document.addEventListener('touchstart', this, options);
|
|
67
|
-
document.addEventListener('mouseup', this, options);
|
|
68
|
-
document.addEventListener('touchend', this, options);
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "handleEvent",
|
|
73
|
-
value: function handleEvent(event) {
|
|
74
|
-
switch (event.type) {
|
|
75
|
-
case 'mouseenter':
|
|
76
|
-
case 'mousemove':
|
|
77
|
-
case 'touchmove':
|
|
78
|
-
this.handler(event);
|
|
79
|
-
break;
|
|
80
|
-
|
|
81
|
-
case 'mousedown':
|
|
82
|
-
case 'touchstart':
|
|
83
|
-
this.downHandler();
|
|
84
|
-
break;
|
|
85
|
-
|
|
86
|
-
case 'mouseup':
|
|
87
|
-
case 'touchend':
|
|
88
|
-
this.upHandler();
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "kill",
|
|
94
|
-
value: function kill() {
|
|
95
|
-
document.removeEventListener('mousemove', this);
|
|
96
|
-
document.removeEventListener('touchmove', this);
|
|
97
|
-
document.removeEventListener('mousedown', this);
|
|
98
|
-
document.removeEventListener('touchstart', this);
|
|
99
|
-
document.removeEventListener('mouseup', this);
|
|
100
|
-
document.removeEventListener('touchend', this);
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
}, {
|
|
104
|
-
key: "handler",
|
|
105
|
-
value: function handler(event) {
|
|
106
|
-
this.updateValues(event);
|
|
107
|
-
this.trigger(this.props);
|
|
108
|
-
}
|
|
109
|
-
}, {
|
|
110
|
-
key: "downHandler",
|
|
111
|
-
value: function downHandler() {
|
|
112
|
-
this.isDown = true;
|
|
113
|
-
this.trigger(this.props);
|
|
114
|
-
}
|
|
115
|
-
}, {
|
|
116
|
-
key: "upHandler",
|
|
117
|
-
value: function upHandler() {
|
|
118
|
-
this.isDown = false;
|
|
119
|
-
this.trigger(this.props);
|
|
120
|
-
}
|
|
121
|
-
}, {
|
|
122
|
-
key: "updateValues",
|
|
123
|
-
value: function updateValues(event) {
|
|
124
|
-
var _event$touches$, _event$touches$2;
|
|
125
|
-
|
|
126
|
-
this.event = event;
|
|
127
|
-
this.yLast = this.y;
|
|
128
|
-
this.xLast = this.x;
|
|
129
|
-
var y = isTouchEvent(event) ? (_event$touches$ = event.touches[0]) === null || _event$touches$ === void 0 ? void 0 : _event$touches$.clientY : event.clientY;
|
|
130
|
-
|
|
131
|
-
if (y !== this.y) {
|
|
132
|
-
this.y = y;
|
|
133
|
-
}
|
|
90
|
+
updateValues(event) {
|
|
91
|
+
var _event$touches$, _event$touches$2;
|
|
134
92
|
|
|
135
|
-
|
|
93
|
+
this.event = event;
|
|
94
|
+
this.yLast = this.y;
|
|
95
|
+
this.xLast = this.x;
|
|
96
|
+
var y = isTouchEvent(event) ? (_event$touches$ = event.touches[0]) === null || _event$touches$ === void 0 ? void 0 : _event$touches$.clientY : event.clientY;
|
|
136
97
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
98
|
+
if (y !== this.y) {
|
|
99
|
+
this.y = y;
|
|
140
100
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
isDown: this.isDown,
|
|
147
|
-
x: this.x,
|
|
148
|
-
y: this.y,
|
|
149
|
-
changed: {
|
|
150
|
-
x: this.x !== this.xLast,
|
|
151
|
-
y: this.y !== this.yLast
|
|
152
|
-
},
|
|
153
|
-
last: {
|
|
154
|
-
x: this.xLast,
|
|
155
|
-
y: this.yLast
|
|
156
|
-
},
|
|
157
|
-
delta: {
|
|
158
|
-
x: this.x - this.xLast,
|
|
159
|
-
y: this.y - this.yLast
|
|
160
|
-
},
|
|
161
|
-
progress: {
|
|
162
|
-
x: this.x / window.innerWidth,
|
|
163
|
-
y: this.y / window.innerHeight
|
|
164
|
-
},
|
|
165
|
-
max: {
|
|
166
|
-
x: window.innerWidth,
|
|
167
|
-
y: window.innerHeight
|
|
168
|
-
}
|
|
169
|
-
};
|
|
101
|
+
|
|
102
|
+
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
|
+
|
|
104
|
+
if (x !== this.x) {
|
|
105
|
+
this.x = x;
|
|
170
106
|
}
|
|
171
|
-
}
|
|
107
|
+
}
|
|
172
108
|
|
|
173
|
-
|
|
174
|
-
|
|
109
|
+
get props() {
|
|
110
|
+
return {
|
|
111
|
+
event: this.event,
|
|
112
|
+
isDown: this.isDown,
|
|
113
|
+
x: this.x,
|
|
114
|
+
y: this.y,
|
|
115
|
+
changed: {
|
|
116
|
+
x: this.x !== this.xLast,
|
|
117
|
+
y: this.y !== this.yLast
|
|
118
|
+
},
|
|
119
|
+
last: {
|
|
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
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
175
139
|
|
|
176
140
|
var pointer = null;
|
|
177
141
|
export default function usePointer() {
|
|
@@ -183,15 +147,12 @@ export default function usePointer() {
|
|
|
183
147
|
var remove = pointer.remove.bind(pointer);
|
|
184
148
|
var has = pointer.has.bind(pointer);
|
|
185
149
|
|
|
186
|
-
var props =
|
|
187
|
-
return pointer.props;
|
|
188
|
-
};
|
|
150
|
+
var props = () => pointer.props;
|
|
189
151
|
|
|
190
152
|
return {
|
|
191
|
-
add
|
|
192
|
-
remove
|
|
193
|
-
has
|
|
194
|
-
props
|
|
153
|
+
add,
|
|
154
|
+
remove,
|
|
155
|
+
has,
|
|
156
|
+
props
|
|
195
157
|
};
|
|
196
|
-
}
|
|
197
|
-
//# sourceMappingURL=pointer.js.map
|
|
158
|
+
}
|