@studiometa/js-toolkit 2.0.0-beta.9 → 2.0.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/Base/index.cjs +284 -0
- package/Base/index.d.ts +36 -28
- package/Base/index.js +113 -197
- package/Base/managers/ChildrenManager.cjs +146 -0
- package/Base/managers/ChildrenManager.d.ts +11 -3
- package/Base/managers/ChildrenManager.js +60 -59
- package/Base/managers/EventsManager.cjs +183 -0
- package/Base/managers/EventsManager.d.ts +13 -20
- package/Base/managers/EventsManager.js +72 -112
- package/Base/managers/OptionsManager.cjs +173 -0
- package/Base/managers/OptionsManager.d.ts +20 -13
- package/Base/managers/OptionsManager.js +60 -91
- package/Base/managers/RefsManager.cjs +99 -0
- package/Base/managers/RefsManager.d.ts +4 -4
- package/Base/managers/RefsManager.js +28 -38
- package/Base/managers/ServicesManager.cjs +134 -0
- package/Base/managers/ServicesManager.d.ts +14 -8
- package/Base/managers/ServicesManager.js +42 -67
- package/Base/utils.cjs +41 -0
- package/Base/utils.d.ts +4 -4
- package/Base/utils.js +12 -11
- package/decorators/index.cjs +45 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +20 -8
- package/decorators/withBreakpointManager.cjs +84 -0
- package/decorators/withBreakpointManager.d.ts +2 -2
- package/decorators/withBreakpointManager.js +18 -40
- package/decorators/withBreakpointObserver.cjs +114 -0
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js +45 -88
- package/decorators/withDrag.cjs +53 -0
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withDrag.js +24 -26
- package/decorators/withExtraConfig.cjs +43 -0
- package/decorators/withExtraConfig.d.ts +1 -1
- package/decorators/withExtraConfig.js +17 -12
- package/decorators/withFreezedOptions.cjs +37 -0
- package/decorators/withFreezedOptions.d.ts +14 -0
- package/decorators/withFreezedOptions.js +15 -0
- package/decorators/withIntersectionObserver.cjs +61 -0
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js +29 -33
- package/decorators/withMountWhenInView.cjs +68 -0
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js +31 -53
- package/decorators/withScrolledInView.cjs +114 -0
- package/decorators/withScrolledInView.d.ts +1 -1
- package/decorators/withScrolledInView.js +35 -39
- package/decorators/withVue2.cjs +61 -0
- package/decorators/withVue2.js +27 -32
- package/helpers/createApp.cjs +52 -0
- package/helpers/createApp.d.ts +3 -26
- package/helpers/createApp.js +12 -12
- package/helpers/getInstanceFromElement.cjs +32 -0
- package/helpers/getInstanceFromElement.d.ts +14 -0
- package/helpers/getInstanceFromElement.js +10 -0
- package/helpers/importOnInteraction.cjs +52 -0
- package/helpers/importOnInteraction.d.ts +3 -5
- package/helpers/importOnInteraction.js +17 -18
- package/helpers/importWhenIdle.cjs +49 -0
- package/helpers/importWhenIdle.d.ts +3 -5
- package/helpers/importWhenIdle.js +14 -17
- package/helpers/importWhenVisible.cjs +50 -0
- package/helpers/importWhenVisible.d.ts +4 -6
- package/helpers/importWhenVisible.js +16 -18
- package/helpers/index.cjs +37 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +12 -4
- package/helpers/utils.cjs +35 -0
- package/helpers/utils.d.ts +3 -4
- package/helpers/utils.js +7 -6
- package/index.cjs +33 -0
- package/index.js +7 -4
- package/package.json +14 -4
- package/services/Service.cjs +76 -0
- package/services/Service.d.ts +9 -9
- package/services/Service.js +19 -32
- package/services/drag.cjs +212 -0
- package/services/drag.d.ts +3 -2
- package/services/drag.js +64 -69
- package/services/index.cjs +41 -0
- package/services/index.js +16 -7
- package/services/key.cjs +104 -0
- package/services/key.d.ts +1 -1
- package/services/key.js +28 -36
- package/services/load.cjs +72 -0
- package/services/load.d.ts +1 -1
- package/services/load.js +17 -19
- package/services/pointer.cjs +162 -0
- package/services/pointer.d.ts +1 -1
- package/services/pointer.js +43 -60
- package/services/raf.cjs +83 -0
- package/services/raf.d.ts +1 -1
- package/services/raf.js +20 -28
- package/services/resize.cjs +108 -0
- package/services/resize.d.ts +1 -1
- package/services/resize.js +33 -42
- package/services/scroll.cjs +131 -0
- package/services/scroll.d.ts +1 -1
- package/services/scroll.js +26 -35
- package/utils/collide/boundingRectToCircle.cjs +34 -0
- package/utils/collide/boundingRectToCircle.d.ts +6 -6
- package/utils/collide/boundingRectToCircle.js +7 -10
- package/utils/collide/collideCircleCircle.cjs +34 -0
- package/utils/collide/collideCircleCircle.d.ts +4 -4
- package/utils/collide/collideCircleCircle.js +8 -7
- package/utils/collide/collideCircleRect.cjs +46 -0
- package/utils/collide/collideCircleRect.d.ts +8 -8
- package/utils/collide/collideCircleRect.js +10 -12
- package/utils/collide/collidePointCircle.cjs +31 -0
- package/utils/collide/collidePointCircle.d.ts +6 -6
- package/utils/collide/collidePointCircle.js +8 -5
- package/utils/collide/collidePointRect.cjs +28 -0
- package/utils/collide/collidePointRect.d.ts +7 -7
- package/utils/collide/collidePointRect.js +5 -2
- package/utils/collide/collideRectRect.cjs +28 -0
- package/utils/collide/collideRectRect.d.ts +5 -5
- package/utils/collide/collideRectRect.js +5 -2
- package/utils/collide/index.cjs +39 -0
- package/utils/collide/index.js +14 -6
- package/utils/css/classes.cjs +47 -0
- package/utils/css/classes.d.ts +13 -12
- package/utils/css/classes.js +19 -15
- package/utils/css/index.cjs +38 -0
- package/utils/css/index.d.ts +2 -2
- package/utils/css/index.js +13 -6
- package/utils/css/matrix.cjs +30 -0
- package/utils/css/matrix.d.ts +14 -15
- package/utils/css/matrix.js +7 -5
- package/utils/css/styles.cjs +44 -0
- package/utils/css/styles.d.ts +8 -20
- package/utils/css/styles.js +12 -12
- package/utils/css/transition.cjs +120 -0
- package/utils/css/transition.d.ts +15 -9
- package/utils/css/transition.js +70 -119
- package/utils/debounce.cjs +34 -0
- package/utils/debounce.d.ts +4 -4
- package/utils/debounce.js +7 -9
- package/utils/focusTrap.cjs +82 -0
- package/utils/focusTrap.d.ts +1 -0
- package/utils/focusTrap.js +31 -22
- package/utils/history.cjs +89 -0
- package/utils/history.d.ts +13 -11
- package/utils/history.js +28 -57
- package/utils/index.cjs +54 -0
- package/utils/index.d.ts +4 -1
- package/utils/index.js +32 -11
- package/utils/keyCodes.cjs +35 -0
- package/utils/keyCodes.js +5 -2
- package/utils/math/clamp.cjs +28 -0
- package/utils/math/clamp.d.ts +1 -1
- package/utils/math/clamp.js +5 -2
- package/utils/math/clamp01.cjs +32 -0
- package/utils/math/clamp01.d.ts +1 -1
- package/utils/math/clamp01.js +6 -3
- package/utils/math/damp.cjs +28 -0
- package/utils/math/damp.d.ts +6 -6
- package/utils/math/damp.js +5 -4
- package/utils/math/ease.cjs +88 -0
- package/utils/math/ease.d.ts +7 -7
- package/utils/math/ease.js +50 -25
- package/utils/math/index.cjs +43 -0
- package/utils/math/index.js +17 -8
- package/utils/math/inertiaFinalValue.cjs +37 -0
- package/utils/math/inertiaFinalValue.d.ts +5 -5
- package/utils/math/inertiaFinalValue.js +8 -10
- package/utils/math/lerp.cjs +28 -0
- package/utils/math/lerp.d.ts +4 -4
- package/utils/math/lerp.js +5 -2
- package/utils/math/map.cjs +28 -0
- package/utils/math/map.d.ts +6 -6
- package/utils/math/map.js +5 -2
- package/utils/math/round.cjs +28 -0
- package/utils/math/round.d.ts +4 -4
- package/utils/math/round.js +5 -3
- package/utils/memoize.cjs +43 -0
- package/utils/memoize.d.ts +1 -1
- package/utils/memoize.js +10 -19
- package/utils/nextFrame.cjs +38 -0
- package/utils/nextFrame.d.ts +6 -6
- package/utils/nextFrame.js +13 -10
- package/utils/nextMicrotask.cjs +28 -0
- package/utils/nextMicrotask.d.ts +8 -0
- package/utils/nextMicrotask.js +6 -0
- package/utils/nextTick.cjs +30 -0
- package/utils/nextTick.d.ts +8 -0
- package/utils/nextTick.js +8 -0
- package/utils/object/autoBind.cjs +49 -0
- package/utils/object/autoBind.d.ts +3 -3
- package/utils/object/autoBind.js +12 -22
- package/utils/object/getAllProperties.cjs +37 -0
- package/utils/object/getAllProperties.d.ts +3 -3
- package/utils/object/getAllProperties.js +10 -13
- package/utils/object/index.cjs +33 -0
- package/utils/object/index.js +8 -3
- package/utils/object/isObject.cjs +28 -0
- package/utils/object/isObject.d.ts +1 -1
- package/utils/object/isObject.js +6 -3
- package/utils/scrollTo.cjs +80 -0
- package/utils/scrollTo.d.ts +1 -1
- package/utils/scrollTo.js +20 -40
- package/utils/string/index.cjs +47 -0
- package/utils/string/index.js +22 -10
- package/utils/string/withLeadingCharacters.cjs +32 -0
- package/utils/string/withLeadingCharacters.d.ts +3 -2
- package/utils/string/withLeadingCharacters.js +7 -4
- package/utils/string/withLeadingSlash.cjs +32 -0
- package/utils/string/withLeadingSlash.d.ts +1 -1
- package/utils/string/withLeadingSlash.js +7 -4
- package/utils/string/withTrailingCharacters.cjs +32 -0
- package/utils/string/withTrailingCharacters.d.ts +3 -2
- package/utils/string/withTrailingCharacters.js +7 -4
- package/utils/string/withTrailingSlash.cjs +32 -0
- package/utils/string/withTrailingSlash.d.ts +1 -1
- package/utils/string/withTrailingSlash.js +7 -4
- package/utils/string/withoutLeadingCharacters.cjs +28 -0
- package/utils/string/withoutLeadingCharacters.d.ts +3 -2
- package/utils/string/withoutLeadingCharacters.js +6 -3
- package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
- package/utils/string/withoutLeadingSlash.cjs +32 -0
- package/utils/string/withoutLeadingSlash.d.ts +1 -1
- package/utils/string/withoutLeadingSlash.js +7 -4
- package/utils/string/withoutTrailingCharacters.cjs +28 -0
- package/utils/string/withoutTrailingCharacters.d.ts +3 -2
- package/utils/string/withoutTrailingCharacters.js +6 -3
- package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
- package/utils/string/withoutTrailingSlash.cjs +32 -0
- package/utils/string/withoutTrailingSlash.d.ts +1 -1
- package/utils/string/withoutTrailingSlash.js +7 -4
- package/utils/throttle.cjs +36 -0
- package/utils/throttle.d.ts +3 -3
- package/utils/throttle.js +9 -9
- package/index.modern.js +0 -1
- package/index.umd.js +0 -1
package/services/drag.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import Service from './Service.js';
|
|
8
|
-
import usePointer from './pointer.js';
|
|
9
|
-
import useRaf from './raf.js';
|
|
10
|
-
import inertiaFinalValue from '../utils/math/inertiaFinalValue.js';
|
|
11
|
-
var MODES = {
|
|
12
|
-
START: 'start',
|
|
13
|
-
DRAG: 'drag',
|
|
14
|
-
DROP: 'drop',
|
|
15
|
-
INERTIA: 'inertia',
|
|
16
|
-
STOP: 'stop'
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
17
6
|
};
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
import Service from "./Service.js";
|
|
8
|
+
import usePointer from "./pointer.js";
|
|
9
|
+
import useRaf from "./raf.js";
|
|
10
|
+
import inertiaFinalValue from "../utils/math/inertiaFinalValue.js";
|
|
11
|
+
const MODES = {
|
|
12
|
+
START: "start",
|
|
13
|
+
DRAG: "drag",
|
|
14
|
+
DROP: "drop",
|
|
15
|
+
INERTIA: "inertia",
|
|
16
|
+
STOP: "stop"
|
|
17
|
+
};
|
|
18
|
+
let id = 0;
|
|
20
19
|
class Drag extends Service {
|
|
21
|
-
constructor(target) {
|
|
22
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
20
|
+
constructor(target, options = {}) {
|
|
23
21
|
super();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "props", {
|
|
22
|
+
__publicField(this, "id");
|
|
23
|
+
__publicField(this, "props", {
|
|
28
24
|
target: null,
|
|
29
|
-
mode:
|
|
25
|
+
mode: void 0,
|
|
30
26
|
isGrabbing: false,
|
|
31
27
|
hasInertia: false,
|
|
32
28
|
x: 0,
|
|
@@ -48,45 +44,53 @@ class Drag extends Service {
|
|
|
48
44
|
y: 0
|
|
49
45
|
}
|
|
50
46
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
__publicField(this, "options", {
|
|
48
|
+
dampFactor: 0.85,
|
|
49
|
+
dragTreshold: 10
|
|
54
50
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.id = "drag-".concat(instanceIds);
|
|
51
|
+
id += 1;
|
|
52
|
+
this.id = `drag-${id}`;
|
|
58
53
|
this.props.target = target;
|
|
59
|
-
this.options =
|
|
54
|
+
this.options = { ...this.options, ...options };
|
|
60
55
|
this.pointerHandler = this.pointerHandler.bind(this);
|
|
61
56
|
this.rafHandler = this.rafHandler.bind(this);
|
|
62
|
-
return this;
|
|
63
57
|
}
|
|
64
|
-
|
|
65
58
|
init() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.props.target.addEventListener(
|
|
70
|
-
this.props.target.addEventListener(
|
|
71
|
-
|
|
59
|
+
const options = { passive: true };
|
|
60
|
+
this.props.target.addEventListener("mousedown", this, options);
|
|
61
|
+
this.props.target.addEventListener("touchstart", this, options);
|
|
62
|
+
this.props.target.addEventListener("dragstart", this, { capture: true });
|
|
63
|
+
this.props.target.addEventListener("click", this, { capture: true });
|
|
64
|
+
const pointer = usePointer();
|
|
72
65
|
pointer.add(this.id, this.pointerHandler);
|
|
73
66
|
return this;
|
|
74
67
|
}
|
|
75
|
-
|
|
76
68
|
kill() {
|
|
77
|
-
this.props.target.removeEventListener(
|
|
78
|
-
this.props.target.removeEventListener(
|
|
79
|
-
|
|
69
|
+
this.props.target.removeEventListener("mousedown", this);
|
|
70
|
+
this.props.target.removeEventListener("touchstart", this);
|
|
71
|
+
this.props.target.removeEventListener("dragstart", this);
|
|
72
|
+
this.props.target.removeEventListener("click", this);
|
|
73
|
+
const pointer = usePointer();
|
|
80
74
|
pointer.remove(this.id);
|
|
81
75
|
return this;
|
|
82
76
|
}
|
|
83
|
-
|
|
84
77
|
handleEvent(event) {
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
if (event.type === "dragstart") {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (event.type === "click") {
|
|
83
|
+
if (this.__shouldPreventClick) {
|
|
84
|
+
event.stopImmediatePropagation();
|
|
85
|
+
event.stopPropagation();
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
|
|
91
|
+
const y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
|
|
87
92
|
this.start(x, y);
|
|
88
93
|
}
|
|
89
|
-
|
|
90
94
|
start(x, y) {
|
|
91
95
|
this.props.x = x;
|
|
92
96
|
this.props.y = y;
|
|
@@ -102,7 +106,6 @@ class Drag extends Service {
|
|
|
102
106
|
this.props.isGrabbing = true;
|
|
103
107
|
this.trigger(this.props);
|
|
104
108
|
}
|
|
105
|
-
|
|
106
109
|
drop() {
|
|
107
110
|
this.props.isGrabbing = false;
|
|
108
111
|
this.props.mode = MODES.DROP;
|
|
@@ -111,19 +114,17 @@ class Drag extends Service {
|
|
|
111
114
|
this.props.final.y = inertiaFinalValue(this.props.y, this.props.delta.y, this.options.dampFactor);
|
|
112
115
|
this.trigger(this.props);
|
|
113
116
|
setTimeout(() => {
|
|
114
|
-
|
|
117
|
+
const raf = useRaf();
|
|
115
118
|
raf.remove(this.id);
|
|
116
119
|
raf.add(this.id, this.rafHandler);
|
|
117
120
|
}, 0);
|
|
118
121
|
}
|
|
119
|
-
|
|
120
122
|
stop() {
|
|
121
123
|
useRaf().remove(this.id);
|
|
122
124
|
this.props.hasInertia = false;
|
|
123
125
|
this.props.mode = MODES.STOP;
|
|
124
126
|
this.trigger(this.props);
|
|
125
127
|
}
|
|
126
|
-
|
|
127
128
|
rafHandler() {
|
|
128
129
|
if (!this.props.isGrabbing) {
|
|
129
130
|
this.props.x += this.props.delta.x;
|
|
@@ -132,19 +133,15 @@ class Drag extends Service {
|
|
|
132
133
|
this.props.distance.y = this.props.y - this.props.origin.y;
|
|
133
134
|
this.props.delta.x *= this.options.dampFactor;
|
|
134
135
|
this.props.delta.y *= this.options.dampFactor;
|
|
135
|
-
|
|
136
136
|
if (this.props.mode !== MODES.INERTIA) {
|
|
137
137
|
this.props.mode = MODES.INERTIA;
|
|
138
138
|
}
|
|
139
|
-
|
|
140
139
|
this.trigger(this.props);
|
|
141
|
-
|
|
142
140
|
if (Math.abs(this.props.delta.x) < 0.1 && Math.abs(this.props.delta.y) < 0.1) {
|
|
143
141
|
this.stop();
|
|
144
142
|
}
|
|
145
143
|
}
|
|
146
144
|
}
|
|
147
|
-
|
|
148
145
|
pointerHandler(props) {
|
|
149
146
|
if (this.props.isGrabbing) {
|
|
150
147
|
this.props.x = props.x;
|
|
@@ -155,31 +152,27 @@ class Drag extends Service {
|
|
|
155
152
|
this.props.final.y = props.y;
|
|
156
153
|
this.props.distance.x = this.props.x - this.props.origin.x;
|
|
157
154
|
this.props.distance.y = this.props.y - this.props.origin.y;
|
|
158
|
-
|
|
159
155
|
if (this.props.mode !== MODES.DRAG) {
|
|
160
156
|
this.props.mode = MODES.DRAG;
|
|
161
157
|
}
|
|
162
|
-
|
|
163
158
|
this.trigger(this.props);
|
|
164
|
-
|
|
165
159
|
if (!props.isDown) {
|
|
166
160
|
this.drop();
|
|
167
161
|
}
|
|
168
162
|
}
|
|
169
163
|
}
|
|
170
|
-
|
|
171
164
|
updateProps() {
|
|
172
165
|
return this.props;
|
|
173
166
|
}
|
|
174
|
-
|
|
167
|
+
get __shouldPreventClick() {
|
|
168
|
+
return Math.abs(this.props.distance.x) > this.options.dragTreshold || Math.abs(this.props.distance.y) > this.options.dragTreshold;
|
|
169
|
+
}
|
|
175
170
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var drag = instances.get(target);
|
|
180
|
-
|
|
171
|
+
const instances = /* @__PURE__ */ new WeakMap();
|
|
172
|
+
function useDrag(target, options) {
|
|
173
|
+
let drag = instances.get(target);
|
|
181
174
|
if (!drag) {
|
|
182
|
-
|
|
175
|
+
const instance = new Drag(target, options);
|
|
183
176
|
drag = {
|
|
184
177
|
add: instance.add.bind(instance),
|
|
185
178
|
remove: instance.remove.bind(instance),
|
|
@@ -188,6 +181,8 @@ export default function useDrag(target, options) {
|
|
|
188
181
|
};
|
|
189
182
|
instances.set(target, drag);
|
|
190
183
|
}
|
|
191
|
-
|
|
192
184
|
return drag;
|
|
193
|
-
}
|
|
185
|
+
}
|
|
186
|
+
export {
|
|
187
|
+
useDrag as default
|
|
188
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// packages/js-toolkit/services/index.js
|
|
23
|
+
var services_exports = {};
|
|
24
|
+
__export(services_exports, {
|
|
25
|
+
useDrag: () => import_drag.default,
|
|
26
|
+
useKey: () => import_key.default,
|
|
27
|
+
useLoad: () => import_load.default,
|
|
28
|
+
usePointer: () => import_pointer.default,
|
|
29
|
+
useRaf: () => import_raf.default,
|
|
30
|
+
useResize: () => import_resize.default,
|
|
31
|
+
useScroll: () => import_scroll.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(services_exports);
|
|
34
|
+
var import_drag = __toESM(require("./drag.cjs"), 1);
|
|
35
|
+
var import_key = __toESM(require("./key.cjs"), 1);
|
|
36
|
+
var import_load = __toESM(require("./load.cjs"), 1);
|
|
37
|
+
var import_pointer = __toESM(require("./pointer.cjs"), 1);
|
|
38
|
+
var import_raf = __toESM(require("./raf.cjs"), 1);
|
|
39
|
+
var import_resize = __toESM(require("./resize.cjs"), 1);
|
|
40
|
+
var import_scroll = __toESM(require("./scroll.cjs"), 1);
|
|
41
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/services/index.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { default as default2 } from "./drag.js";
|
|
2
|
+
import { default as default3 } from "./key.js";
|
|
3
|
+
import { default as default4 } from "./load.js";
|
|
4
|
+
import { default as default5 } from "./pointer.js";
|
|
5
|
+
import { default as default6 } from "./raf.js";
|
|
6
|
+
import { default as default7 } from "./resize.js";
|
|
7
|
+
import { default as default8 } from "./scroll.js";
|
|
8
|
+
export {
|
|
9
|
+
default2 as useDrag,
|
|
10
|
+
default3 as useKey,
|
|
11
|
+
default4 as useLoad,
|
|
12
|
+
default5 as usePointer,
|
|
13
|
+
default6 as useRaf,
|
|
14
|
+
default7 as useResize,
|
|
15
|
+
default8 as useScroll
|
|
16
|
+
};
|
package/services/key.cjs
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key2 of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
16
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key2, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// packages/js-toolkit/services/key.js
|
|
28
|
+
var key_exports = {};
|
|
29
|
+
__export(key_exports, {
|
|
30
|
+
default: () => useKey
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(key_exports);
|
|
33
|
+
var import_Service = __toESM(require("./Service.cjs"), 1);
|
|
34
|
+
var import_keyCodes = __toESM(require("../utils/keyCodes.cjs"), 1);
|
|
35
|
+
var Key = class extends import_Service.default {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
__publicField(this, "previousEvent");
|
|
39
|
+
__publicField(this, "props", {
|
|
40
|
+
event: null,
|
|
41
|
+
triggered: 0,
|
|
42
|
+
isUp: false,
|
|
43
|
+
isDown: false,
|
|
44
|
+
ENTER: false,
|
|
45
|
+
SPACE: false,
|
|
46
|
+
TAB: false,
|
|
47
|
+
ESC: false,
|
|
48
|
+
LEFT: false,
|
|
49
|
+
UP: false,
|
|
50
|
+
RIGHT: false,
|
|
51
|
+
DOWN: false,
|
|
52
|
+
direction: "none"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
init() {
|
|
56
|
+
document.addEventListener("keydown", this);
|
|
57
|
+
document.addEventListener("keyup", this);
|
|
58
|
+
}
|
|
59
|
+
handleEvent(event) {
|
|
60
|
+
this.updateProps(event);
|
|
61
|
+
this.trigger(this.props);
|
|
62
|
+
}
|
|
63
|
+
kill() {
|
|
64
|
+
document.removeEventListener("keydown", this);
|
|
65
|
+
document.removeEventListener("keyup", this);
|
|
66
|
+
}
|
|
67
|
+
updateProps(event) {
|
|
68
|
+
var _a;
|
|
69
|
+
this.props.event = event;
|
|
70
|
+
Object.entries(import_keyCodes.default).forEach(([name, code]) => {
|
|
71
|
+
this.props[name] = code === event.keyCode;
|
|
72
|
+
});
|
|
73
|
+
if (!this.previousEvent) {
|
|
74
|
+
this.props.triggered = 0;
|
|
75
|
+
}
|
|
76
|
+
if (this.props.event.type === "keydown" && ((_a = this.previousEvent) == null ? void 0 : _a.type) === "keydown") {
|
|
77
|
+
this.props.triggered += 1;
|
|
78
|
+
} else {
|
|
79
|
+
this.props.triggered = 1;
|
|
80
|
+
}
|
|
81
|
+
this.previousEvent = this.props.event;
|
|
82
|
+
this.props.direction = this.props.event.type === "keydown" ? "down" : "up";
|
|
83
|
+
this.props.isUp = this.props.event.type === "keyup";
|
|
84
|
+
this.props.isDown = this.props.event.type === "keydown";
|
|
85
|
+
return this.props;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var instance;
|
|
89
|
+
var key;
|
|
90
|
+
function useKey() {
|
|
91
|
+
if (!key) {
|
|
92
|
+
if (!instance) {
|
|
93
|
+
instance = new Key();
|
|
94
|
+
}
|
|
95
|
+
key = {
|
|
96
|
+
add: instance.add.bind(instance),
|
|
97
|
+
remove: instance.remove.bind(instance),
|
|
98
|
+
has: instance.has.bind(instance),
|
|
99
|
+
props: instance.updateProps.bind(instance)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return key;
|
|
103
|
+
}
|
|
104
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/services/key.d.ts
CHANGED
package/services/key.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
|
|
3
|
+
var __publicField = (obj, key2, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import Service from "./Service.js";
|
|
8
|
+
import keyCodes from "../utils/keyCodes.js";
|
|
5
9
|
class Key extends Service {
|
|
6
10
|
constructor() {
|
|
7
11
|
super(...arguments);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
_defineProperty(this, "props", {
|
|
12
|
+
__publicField(this, "previousEvent");
|
|
13
|
+
__publicField(this, "props", {
|
|
12
14
|
event: null,
|
|
13
15
|
triggered: 0,
|
|
14
16
|
isUp: false,
|
|
@@ -21,61 +23,49 @@ class Key extends Service {
|
|
|
21
23
|
UP: false,
|
|
22
24
|
RIGHT: false,
|
|
23
25
|
DOWN: false,
|
|
24
|
-
direction:
|
|
26
|
+
direction: "none"
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
|
-
|
|
28
29
|
init() {
|
|
29
|
-
document.addEventListener(
|
|
30
|
-
document.addEventListener(
|
|
30
|
+
document.addEventListener("keydown", this);
|
|
31
|
+
document.addEventListener("keyup", this);
|
|
31
32
|
}
|
|
32
|
-
|
|
33
33
|
handleEvent(event) {
|
|
34
34
|
this.updateProps(event);
|
|
35
35
|
this.trigger(this.props);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
kill() {
|
|
39
|
-
document.removeEventListener(
|
|
40
|
-
document.removeEventListener(
|
|
38
|
+
document.removeEventListener("keydown", this);
|
|
39
|
+
document.removeEventListener("keyup", this);
|
|
41
40
|
}
|
|
42
|
-
|
|
43
41
|
updateProps(event) {
|
|
44
|
-
var
|
|
45
|
-
|
|
42
|
+
var _a;
|
|
46
43
|
this.props.event = event;
|
|
47
|
-
Object.entries(keyCodes).forEach(
|
|
48
|
-
var [name, code] = _ref;
|
|
44
|
+
Object.entries(keyCodes).forEach(([name, code]) => {
|
|
49
45
|
this.props[name] = code === event.keyCode;
|
|
50
46
|
});
|
|
51
|
-
|
|
52
47
|
if (!this.previousEvent) {
|
|
53
48
|
this.props.triggered = 0;
|
|
54
49
|
}
|
|
55
|
-
|
|
56
|
-
if (this.props.event.type === 'keydown' && ((_this$previousEvent = this.previousEvent) === null || _this$previousEvent === void 0 ? void 0 : _this$previousEvent.type) === 'keydown') {
|
|
50
|
+
if (this.props.event.type === "keydown" && ((_a = this.previousEvent) == null ? void 0 : _a.type) === "keydown") {
|
|
57
51
|
this.props.triggered += 1;
|
|
58
52
|
} else {
|
|
59
53
|
this.props.triggered = 1;
|
|
60
54
|
}
|
|
61
|
-
|
|
62
55
|
this.previousEvent = this.props.event;
|
|
63
|
-
this.props.direction = this.props.event.type ===
|
|
64
|
-
this.props.isUp = this.props.event.type ===
|
|
65
|
-
this.props.isDown = this.props.event.type ===
|
|
56
|
+
this.props.direction = this.props.event.type === "keydown" ? "down" : "up";
|
|
57
|
+
this.props.isUp = this.props.event.type === "keyup";
|
|
58
|
+
this.props.isDown = this.props.event.type === "keydown";
|
|
66
59
|
return this.props;
|
|
67
60
|
}
|
|
68
|
-
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export default function useKey() {
|
|
62
|
+
let instance;
|
|
63
|
+
let key;
|
|
64
|
+
function useKey() {
|
|
74
65
|
if (!key) {
|
|
75
66
|
if (!instance) {
|
|
76
67
|
instance = new Key();
|
|
77
68
|
}
|
|
78
|
-
|
|
79
69
|
key = {
|
|
80
70
|
add: instance.add.bind(instance),
|
|
81
71
|
remove: instance.remove.bind(instance),
|
|
@@ -83,6 +73,8 @@ export default function useKey() {
|
|
|
83
73
|
props: instance.updateProps.bind(instance)
|
|
84
74
|
};
|
|
85
75
|
}
|
|
86
|
-
|
|
87
76
|
return key;
|
|
88
|
-
}
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
useKey as default
|
|
80
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// packages/js-toolkit/services/load.js
|
|
28
|
+
var load_exports = {};
|
|
29
|
+
__export(load_exports, {
|
|
30
|
+
default: () => useLoad
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(load_exports);
|
|
33
|
+
var import_Service = __toESM(require("./Service.cjs"), 1);
|
|
34
|
+
var Load = class extends import_Service.default {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
__publicField(this, "props", {
|
|
38
|
+
time: window.performance.now()
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
init() {
|
|
42
|
+
window.addEventListener("load", this);
|
|
43
|
+
}
|
|
44
|
+
handleEvent() {
|
|
45
|
+
this.updateProps();
|
|
46
|
+
this.trigger(this.props);
|
|
47
|
+
}
|
|
48
|
+
kill() {
|
|
49
|
+
window.removeEventListener("load", this);
|
|
50
|
+
}
|
|
51
|
+
updateProps() {
|
|
52
|
+
this.props.time = window.performance.now();
|
|
53
|
+
return this.props;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var instance;
|
|
57
|
+
var load;
|
|
58
|
+
function useLoad() {
|
|
59
|
+
if (!load) {
|
|
60
|
+
if (!instance) {
|
|
61
|
+
instance = new Load();
|
|
62
|
+
}
|
|
63
|
+
load = {
|
|
64
|
+
add: instance.add.bind(instance),
|
|
65
|
+
remove: instance.remove.bind(instance),
|
|
66
|
+
has: instance.has.bind(instance),
|
|
67
|
+
props: instance.updateProps.bind(instance)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return load;
|
|
71
|
+
}
|
|
72
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/services/load.d.ts
CHANGED
package/services/load.js
CHANGED
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import Service from "./Service.js";
|
|
4
8
|
class Load extends Service {
|
|
5
9
|
constructor() {
|
|
6
10
|
super(...arguments);
|
|
7
|
-
|
|
8
|
-
_defineProperty(this, "props", {
|
|
11
|
+
__publicField(this, "props", {
|
|
9
12
|
time: window.performance.now()
|
|
10
13
|
});
|
|
11
14
|
}
|
|
12
|
-
|
|
13
15
|
init() {
|
|
14
|
-
window.addEventListener(
|
|
16
|
+
window.addEventListener("load", this);
|
|
15
17
|
}
|
|
16
|
-
|
|
17
18
|
handleEvent() {
|
|
18
19
|
this.updateProps();
|
|
19
20
|
this.trigger(this.props);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
22
|
kill() {
|
|
23
|
-
window.removeEventListener(
|
|
23
|
+
window.removeEventListener("load", this);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
25
|
updateProps() {
|
|
27
26
|
this.props.time = window.performance.now();
|
|
28
27
|
return this.props;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export default function useLoad() {
|
|
30
|
+
let instance;
|
|
31
|
+
let load;
|
|
32
|
+
function useLoad() {
|
|
36
33
|
if (!load) {
|
|
37
34
|
if (!instance) {
|
|
38
35
|
instance = new Load();
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
load = {
|
|
42
38
|
add: instance.add.bind(instance),
|
|
43
39
|
remove: instance.remove.bind(instance),
|
|
@@ -45,6 +41,8 @@ export default function useLoad() {
|
|
|
45
41
|
props: instance.updateProps.bind(instance)
|
|
46
42
|
};
|
|
47
43
|
}
|
|
48
|
-
|
|
49
44
|
return load;
|
|
50
|
-
}
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
useLoad as default
|
|
48
|
+
};
|