@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.
Files changed (238) hide show
  1. package/Base/index.cjs +284 -0
  2. package/Base/index.d.ts +36 -28
  3. package/Base/index.js +113 -197
  4. package/Base/managers/ChildrenManager.cjs +146 -0
  5. package/Base/managers/ChildrenManager.d.ts +11 -3
  6. package/Base/managers/ChildrenManager.js +60 -59
  7. package/Base/managers/EventsManager.cjs +183 -0
  8. package/Base/managers/EventsManager.d.ts +13 -20
  9. package/Base/managers/EventsManager.js +72 -112
  10. package/Base/managers/OptionsManager.cjs +173 -0
  11. package/Base/managers/OptionsManager.d.ts +20 -13
  12. package/Base/managers/OptionsManager.js +60 -91
  13. package/Base/managers/RefsManager.cjs +99 -0
  14. package/Base/managers/RefsManager.d.ts +4 -4
  15. package/Base/managers/RefsManager.js +28 -38
  16. package/Base/managers/ServicesManager.cjs +134 -0
  17. package/Base/managers/ServicesManager.d.ts +14 -8
  18. package/Base/managers/ServicesManager.js +42 -67
  19. package/Base/utils.cjs +41 -0
  20. package/Base/utils.d.ts +4 -4
  21. package/Base/utils.js +12 -11
  22. package/decorators/index.cjs +45 -0
  23. package/decorators/index.d.ts +1 -0
  24. package/decorators/index.js +20 -8
  25. package/decorators/withBreakpointManager.cjs +84 -0
  26. package/decorators/withBreakpointManager.d.ts +2 -2
  27. package/decorators/withBreakpointManager.js +18 -40
  28. package/decorators/withBreakpointObserver.cjs +114 -0
  29. package/decorators/withBreakpointObserver.d.ts +1 -1
  30. package/decorators/withBreakpointObserver.js +45 -88
  31. package/decorators/withDrag.cjs +53 -0
  32. package/decorators/withDrag.d.ts +1 -1
  33. package/decorators/withDrag.js +24 -26
  34. package/decorators/withExtraConfig.cjs +43 -0
  35. package/decorators/withExtraConfig.d.ts +1 -1
  36. package/decorators/withExtraConfig.js +17 -12
  37. package/decorators/withFreezedOptions.cjs +37 -0
  38. package/decorators/withFreezedOptions.d.ts +14 -0
  39. package/decorators/withFreezedOptions.js +15 -0
  40. package/decorators/withIntersectionObserver.cjs +61 -0
  41. package/decorators/withIntersectionObserver.d.ts +1 -1
  42. package/decorators/withIntersectionObserver.js +29 -33
  43. package/decorators/withMountWhenInView.cjs +68 -0
  44. package/decorators/withMountWhenInView.d.ts +1 -1
  45. package/decorators/withMountWhenInView.js +31 -53
  46. package/decorators/withScrolledInView.cjs +114 -0
  47. package/decorators/withScrolledInView.d.ts +1 -1
  48. package/decorators/withScrolledInView.js +35 -39
  49. package/decorators/withVue2.cjs +61 -0
  50. package/decorators/withVue2.js +27 -32
  51. package/helpers/createApp.cjs +52 -0
  52. package/helpers/createApp.d.ts +3 -26
  53. package/helpers/createApp.js +12 -12
  54. package/helpers/getInstanceFromElement.cjs +32 -0
  55. package/helpers/getInstanceFromElement.d.ts +14 -0
  56. package/helpers/getInstanceFromElement.js +10 -0
  57. package/helpers/importOnInteraction.cjs +52 -0
  58. package/helpers/importOnInteraction.d.ts +3 -5
  59. package/helpers/importOnInteraction.js +17 -18
  60. package/helpers/importWhenIdle.cjs +49 -0
  61. package/helpers/importWhenIdle.d.ts +3 -5
  62. package/helpers/importWhenIdle.js +14 -17
  63. package/helpers/importWhenVisible.cjs +50 -0
  64. package/helpers/importWhenVisible.d.ts +4 -6
  65. package/helpers/importWhenVisible.js +16 -18
  66. package/helpers/index.cjs +37 -0
  67. package/helpers/index.d.ts +1 -0
  68. package/helpers/index.js +12 -4
  69. package/helpers/utils.cjs +35 -0
  70. package/helpers/utils.d.ts +3 -4
  71. package/helpers/utils.js +7 -6
  72. package/index.cjs +33 -0
  73. package/index.js +7 -4
  74. package/package.json +14 -4
  75. package/services/Service.cjs +76 -0
  76. package/services/Service.d.ts +9 -9
  77. package/services/Service.js +19 -32
  78. package/services/drag.cjs +212 -0
  79. package/services/drag.d.ts +3 -2
  80. package/services/drag.js +64 -69
  81. package/services/index.cjs +41 -0
  82. package/services/index.js +16 -7
  83. package/services/key.cjs +104 -0
  84. package/services/key.d.ts +1 -1
  85. package/services/key.js +28 -36
  86. package/services/load.cjs +72 -0
  87. package/services/load.d.ts +1 -1
  88. package/services/load.js +17 -19
  89. package/services/pointer.cjs +162 -0
  90. package/services/pointer.d.ts +1 -1
  91. package/services/pointer.js +43 -60
  92. package/services/raf.cjs +83 -0
  93. package/services/raf.d.ts +1 -1
  94. package/services/raf.js +20 -28
  95. package/services/resize.cjs +108 -0
  96. package/services/resize.d.ts +1 -1
  97. package/services/resize.js +33 -42
  98. package/services/scroll.cjs +131 -0
  99. package/services/scroll.d.ts +1 -1
  100. package/services/scroll.js +26 -35
  101. package/utils/collide/boundingRectToCircle.cjs +34 -0
  102. package/utils/collide/boundingRectToCircle.d.ts +6 -6
  103. package/utils/collide/boundingRectToCircle.js +7 -10
  104. package/utils/collide/collideCircleCircle.cjs +34 -0
  105. package/utils/collide/collideCircleCircle.d.ts +4 -4
  106. package/utils/collide/collideCircleCircle.js +8 -7
  107. package/utils/collide/collideCircleRect.cjs +46 -0
  108. package/utils/collide/collideCircleRect.d.ts +8 -8
  109. package/utils/collide/collideCircleRect.js +10 -12
  110. package/utils/collide/collidePointCircle.cjs +31 -0
  111. package/utils/collide/collidePointCircle.d.ts +6 -6
  112. package/utils/collide/collidePointCircle.js +8 -5
  113. package/utils/collide/collidePointRect.cjs +28 -0
  114. package/utils/collide/collidePointRect.d.ts +7 -7
  115. package/utils/collide/collidePointRect.js +5 -2
  116. package/utils/collide/collideRectRect.cjs +28 -0
  117. package/utils/collide/collideRectRect.d.ts +5 -5
  118. package/utils/collide/collideRectRect.js +5 -2
  119. package/utils/collide/index.cjs +39 -0
  120. package/utils/collide/index.js +14 -6
  121. package/utils/css/classes.cjs +47 -0
  122. package/utils/css/classes.d.ts +13 -12
  123. package/utils/css/classes.js +19 -15
  124. package/utils/css/index.cjs +38 -0
  125. package/utils/css/index.d.ts +2 -2
  126. package/utils/css/index.js +13 -6
  127. package/utils/css/matrix.cjs +30 -0
  128. package/utils/css/matrix.d.ts +14 -15
  129. package/utils/css/matrix.js +7 -5
  130. package/utils/css/styles.cjs +44 -0
  131. package/utils/css/styles.d.ts +8 -20
  132. package/utils/css/styles.js +12 -12
  133. package/utils/css/transition.cjs +120 -0
  134. package/utils/css/transition.d.ts +15 -9
  135. package/utils/css/transition.js +70 -119
  136. package/utils/debounce.cjs +34 -0
  137. package/utils/debounce.d.ts +4 -4
  138. package/utils/debounce.js +7 -9
  139. package/utils/focusTrap.cjs +82 -0
  140. package/utils/focusTrap.d.ts +1 -0
  141. package/utils/focusTrap.js +31 -22
  142. package/utils/history.cjs +89 -0
  143. package/utils/history.d.ts +13 -11
  144. package/utils/history.js +28 -57
  145. package/utils/index.cjs +54 -0
  146. package/utils/index.d.ts +4 -1
  147. package/utils/index.js +32 -11
  148. package/utils/keyCodes.cjs +35 -0
  149. package/utils/keyCodes.js +5 -2
  150. package/utils/math/clamp.cjs +28 -0
  151. package/utils/math/clamp.d.ts +1 -1
  152. package/utils/math/clamp.js +5 -2
  153. package/utils/math/clamp01.cjs +32 -0
  154. package/utils/math/clamp01.d.ts +1 -1
  155. package/utils/math/clamp01.js +6 -3
  156. package/utils/math/damp.cjs +28 -0
  157. package/utils/math/damp.d.ts +6 -6
  158. package/utils/math/damp.js +5 -4
  159. package/utils/math/ease.cjs +88 -0
  160. package/utils/math/ease.d.ts +7 -7
  161. package/utils/math/ease.js +50 -25
  162. package/utils/math/index.cjs +43 -0
  163. package/utils/math/index.js +17 -8
  164. package/utils/math/inertiaFinalValue.cjs +37 -0
  165. package/utils/math/inertiaFinalValue.d.ts +5 -5
  166. package/utils/math/inertiaFinalValue.js +8 -10
  167. package/utils/math/lerp.cjs +28 -0
  168. package/utils/math/lerp.d.ts +4 -4
  169. package/utils/math/lerp.js +5 -2
  170. package/utils/math/map.cjs +28 -0
  171. package/utils/math/map.d.ts +6 -6
  172. package/utils/math/map.js +5 -2
  173. package/utils/math/round.cjs +28 -0
  174. package/utils/math/round.d.ts +4 -4
  175. package/utils/math/round.js +5 -3
  176. package/utils/memoize.cjs +43 -0
  177. package/utils/memoize.d.ts +1 -1
  178. package/utils/memoize.js +10 -19
  179. package/utils/nextFrame.cjs +38 -0
  180. package/utils/nextFrame.d.ts +6 -6
  181. package/utils/nextFrame.js +13 -10
  182. package/utils/nextMicrotask.cjs +28 -0
  183. package/utils/nextMicrotask.d.ts +8 -0
  184. package/utils/nextMicrotask.js +6 -0
  185. package/utils/nextTick.cjs +30 -0
  186. package/utils/nextTick.d.ts +8 -0
  187. package/utils/nextTick.js +8 -0
  188. package/utils/object/autoBind.cjs +49 -0
  189. package/utils/object/autoBind.d.ts +3 -3
  190. package/utils/object/autoBind.js +12 -22
  191. package/utils/object/getAllProperties.cjs +37 -0
  192. package/utils/object/getAllProperties.d.ts +3 -3
  193. package/utils/object/getAllProperties.js +10 -13
  194. package/utils/object/index.cjs +33 -0
  195. package/utils/object/index.js +8 -3
  196. package/utils/object/isObject.cjs +28 -0
  197. package/utils/object/isObject.d.ts +1 -1
  198. package/utils/object/isObject.js +6 -3
  199. package/utils/scrollTo.cjs +80 -0
  200. package/utils/scrollTo.d.ts +1 -1
  201. package/utils/scrollTo.js +20 -40
  202. package/utils/string/index.cjs +47 -0
  203. package/utils/string/index.js +22 -10
  204. package/utils/string/withLeadingCharacters.cjs +32 -0
  205. package/utils/string/withLeadingCharacters.d.ts +3 -2
  206. package/utils/string/withLeadingCharacters.js +7 -4
  207. package/utils/string/withLeadingSlash.cjs +32 -0
  208. package/utils/string/withLeadingSlash.d.ts +1 -1
  209. package/utils/string/withLeadingSlash.js +7 -4
  210. package/utils/string/withTrailingCharacters.cjs +32 -0
  211. package/utils/string/withTrailingCharacters.d.ts +3 -2
  212. package/utils/string/withTrailingCharacters.js +7 -4
  213. package/utils/string/withTrailingSlash.cjs +32 -0
  214. package/utils/string/withTrailingSlash.d.ts +1 -1
  215. package/utils/string/withTrailingSlash.js +7 -4
  216. package/utils/string/withoutLeadingCharacters.cjs +28 -0
  217. package/utils/string/withoutLeadingCharacters.d.ts +3 -2
  218. package/utils/string/withoutLeadingCharacters.js +6 -3
  219. package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
  220. package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
  221. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  222. package/utils/string/withoutLeadingSlash.cjs +32 -0
  223. package/utils/string/withoutLeadingSlash.d.ts +1 -1
  224. package/utils/string/withoutLeadingSlash.js +7 -4
  225. package/utils/string/withoutTrailingCharacters.cjs +28 -0
  226. package/utils/string/withoutTrailingCharacters.d.ts +3 -2
  227. package/utils/string/withoutTrailingCharacters.js +6 -3
  228. package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
  229. package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
  230. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  231. package/utils/string/withoutTrailingSlash.cjs +32 -0
  232. package/utils/string/withoutTrailingSlash.d.ts +1 -1
  233. package/utils/string/withoutTrailingSlash.js +7 -4
  234. package/utils/throttle.cjs +36 -0
  235. package/utils/throttle.d.ts +3 -3
  236. package/utils/throttle.js +9 -9
  237. package/index.modern.js +0 -1
  238. package/index.umd.js +0 -1
package/services/drag.js CHANGED
@@ -1,32 +1,28 @@
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); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
- var instanceIds = 0;
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
- _defineProperty(this, "id", void 0);
26
-
27
- _defineProperty(this, "props", {
22
+ __publicField(this, "id");
23
+ __publicField(this, "props", {
28
24
  target: null,
29
- mode: undefined,
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
- _defineProperty(this, "options", {
53
- dampFactor: 0.85
47
+ __publicField(this, "options", {
48
+ dampFactor: 0.85,
49
+ dragTreshold: 10
54
50
  });
55
-
56
- instanceIds += 1;
57
- this.id = "drag-".concat(instanceIds);
51
+ id += 1;
52
+ this.id = `drag-${id}`;
58
53
  this.props.target = target;
59
- this.options = _objectSpread(_objectSpread({}, this.options), 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
- var options = {
67
- passive: true
68
- };
69
- this.props.target.addEventListener('mousedown', this, options);
70
- this.props.target.addEventListener('touchstart', this, options);
71
- var pointer = usePointer();
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('mousemove', this);
78
- this.props.target.removeEventListener('touchmove', this);
79
- var pointer = usePointer();
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
- var x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
86
- var y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
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
- var raf = useRaf();
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
- var instances = new WeakMap();
178
- export default function useDrag(target, options) {
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
- var instance = new Drag(target, options);
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
- 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';
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
+ };
@@ -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
@@ -9,7 +9,7 @@
9
9
  * props();
10
10
  * ```
11
11
  *
12
- * @return {KeyService}
12
+ * @returns {KeyService}
13
13
  */
14
14
  export default function useKey(): KeyService;
15
15
  export type KeyService = import('./index').ServiceInterface<KeyServiceProps>;
package/services/key.js CHANGED
@@ -1,14 +1,16 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import Service from './Service.js';
3
- import keyCodes from '../utils/keyCodes.js';
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
- _defineProperty(this, "previousEvent", void 0);
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: 'none'
26
+ direction: "none"
25
27
  });
26
28
  }
27
-
28
29
  init() {
29
- document.addEventListener('keydown', this);
30
- document.addEventListener('keyup', this);
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('keydown', this);
40
- document.removeEventListener('keyup', this);
38
+ document.removeEventListener("keydown", this);
39
+ document.removeEventListener("keyup", this);
41
40
  }
42
-
43
41
  updateProps(event) {
44
- var _this$previousEvent;
45
-
42
+ var _a;
46
43
  this.props.event = event;
47
- Object.entries(keyCodes).forEach(_ref => {
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 === 'keydown' ? 'down' : 'up';
64
- this.props.isUp = this.props.event.type === 'keyup';
65
- this.props.isDown = this.props.event.type === 'keydown';
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
- var instance;
72
- var key;
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;
@@ -9,7 +9,7 @@
9
9
  * props();
10
10
  * ```
11
11
  *
12
- * @return {LoadService}
12
+ * @returns {LoadService}
13
13
  */
14
14
  export default function useLoad(): LoadService;
15
15
  export type LoadService = import('./index').ServiceInterface<LoadServiceProps>;
package/services/load.js CHANGED
@@ -1,43 +1,39 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import Service from './Service.js';
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('load', this);
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('load', this);
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
- var instance;
34
- var load;
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
+ };