@studiometa/js-toolkit 2.0.0-beta.7 → 2.0.0-rc.1

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 (189) hide show
  1. package/Base/index.cjs +285 -0
  2. package/Base/index.d.ts +13 -4
  3. package/Base/index.js +114 -197
  4. package/Base/managers/ChildrenManager.cjs +146 -0
  5. package/Base/managers/ChildrenManager.d.ts +9 -1
  6. package/Base/managers/ChildrenManager.js +60 -59
  7. package/Base/managers/EventsManager.cjs +183 -0
  8. package/Base/managers/EventsManager.js +72 -112
  9. package/Base/managers/OptionsManager.cjs +174 -0
  10. package/Base/managers/OptionsManager.d.ts +9 -5
  11. package/Base/managers/OptionsManager.js +60 -90
  12. package/Base/managers/RefsManager.cjs +99 -0
  13. package/Base/managers/RefsManager.js +30 -35
  14. package/Base/managers/ServicesManager.cjs +131 -0
  15. package/Base/managers/ServicesManager.js +39 -67
  16. package/Base/utils.cjs +41 -0
  17. package/Base/utils.js +12 -11
  18. package/README.md +13 -70
  19. package/decorators/index.cjs +45 -0
  20. package/decorators/index.d.ts +9 -9
  21. package/decorators/index.js +20 -9
  22. package/decorators/withBreakpointManager.cjs +85 -0
  23. package/decorators/withBreakpointManager.js +18 -39
  24. package/decorators/withBreakpointObserver.cjs +115 -0
  25. package/decorators/withBreakpointObserver.js +44 -86
  26. package/decorators/withDrag.cjs +53 -0
  27. package/decorators/withDrag.js +24 -26
  28. package/decorators/withExtraConfig.cjs +43 -0
  29. package/decorators/withExtraConfig.js +17 -12
  30. package/decorators/withFreezedOptions.cjs +36 -0
  31. package/decorators/withFreezedOptions.d.ts +14 -0
  32. package/decorators/withFreezedOptions.js +14 -0
  33. package/decorators/withIntersectionObserver.cjs +62 -0
  34. package/decorators/withIntersectionObserver.js +29 -32
  35. package/decorators/withMountWhenInView.cjs +69 -0
  36. package/decorators/withMountWhenInView.js +31 -52
  37. package/decorators/withScrolledInView.cjs +114 -0
  38. package/decorators/withScrolledInView.d.ts +2 -1
  39. package/decorators/withScrolledInView.js +35 -39
  40. package/decorators/withVue2.cjs +60 -0
  41. package/decorators/withVue2.js +26 -32
  42. package/helpers/createApp.cjs +52 -0
  43. package/helpers/createApp.d.ts +2 -2
  44. package/helpers/createApp.js +12 -12
  45. package/helpers/importOnInteraction.cjs +52 -0
  46. package/helpers/importOnInteraction.js +17 -18
  47. package/helpers/importWhenIdle.cjs +49 -0
  48. package/helpers/importWhenIdle.js +14 -17
  49. package/helpers/importWhenVisible.cjs +50 -0
  50. package/helpers/importWhenVisible.js +16 -18
  51. package/helpers/index.cjs +35 -0
  52. package/helpers/index.d.ts +4 -5
  53. package/helpers/index.js +10 -5
  54. package/helpers/utils.cjs +35 -0
  55. package/helpers/utils.js +7 -6
  56. package/index.cjs +33 -0
  57. package/index.d.ts +4 -21
  58. package/index.js +7 -5
  59. package/package.json +14 -4
  60. package/services/Service.cjs +76 -0
  61. package/services/Service.js +19 -32
  62. package/services/drag.cjs +213 -0
  63. package/services/drag.d.ts +1 -0
  64. package/services/drag.js +64 -68
  65. package/services/index.cjs +41 -0
  66. package/services/index.d.ts +7 -8
  67. package/services/index.js +16 -8
  68. package/services/key.cjs +104 -0
  69. package/services/key.js +28 -36
  70. package/services/load.cjs +72 -0
  71. package/services/load.js +17 -19
  72. package/services/pointer.cjs +162 -0
  73. package/services/pointer.js +43 -60
  74. package/services/raf.cjs +83 -0
  75. package/services/raf.js +20 -28
  76. package/services/resize.cjs +108 -0
  77. package/services/resize.js +33 -42
  78. package/services/scroll.cjs +131 -0
  79. package/services/scroll.js +26 -35
  80. package/utils/collide/boundingRectToCircle.cjs +34 -0
  81. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  82. package/utils/collide/boundingRectToCircle.js +7 -10
  83. package/utils/collide/collideCircleCircle.cjs +34 -0
  84. package/utils/collide/collideCircleCircle.js +8 -7
  85. package/utils/collide/collideCircleRect.cjs +46 -0
  86. package/utils/collide/collideCircleRect.js +10 -12
  87. package/utils/collide/collidePointCircle.cjs +31 -0
  88. package/utils/collide/collidePointCircle.js +8 -5
  89. package/utils/collide/collidePointRect.cjs +28 -0
  90. package/utils/collide/collidePointRect.js +5 -2
  91. package/utils/collide/collideRectRect.cjs +28 -0
  92. package/utils/collide/collideRectRect.js +5 -2
  93. package/utils/collide/index.cjs +39 -0
  94. package/utils/collide/index.d.ts +6 -7
  95. package/utils/collide/index.js +14 -7
  96. package/utils/css/classes.cjs +47 -0
  97. package/utils/css/classes.d.ts +10 -9
  98. package/utils/css/classes.js +18 -14
  99. package/utils/css/index.cjs +38 -0
  100. package/utils/css/index.d.ts +4 -5
  101. package/utils/css/index.js +13 -5
  102. package/utils/css/matrix.cjs +30 -0
  103. package/utils/css/matrix.js +7 -5
  104. package/utils/css/styles.cjs +44 -0
  105. package/utils/css/styles.d.ts +6 -18
  106. package/utils/css/styles.js +12 -12
  107. package/utils/css/transition.cjs +120 -0
  108. package/utils/css/transition.d.ts +15 -9
  109. package/utils/css/transition.js +70 -119
  110. package/utils/debounce.cjs +34 -0
  111. package/utils/debounce.js +7 -9
  112. package/utils/focusTrap.cjs +82 -0
  113. package/utils/focusTrap.js +30 -21
  114. package/utils/history.cjs +89 -0
  115. package/utils/history.js +28 -57
  116. package/utils/index.cjs +54 -0
  117. package/utils/index.d.ts +14 -35
  118. package/utils/index.js +32 -17
  119. package/utils/keyCodes.cjs +35 -0
  120. package/utils/keyCodes.js +5 -2
  121. package/utils/math/clamp.cjs +28 -0
  122. package/utils/math/clamp.js +5 -2
  123. package/utils/math/clamp01.cjs +32 -0
  124. package/utils/math/clamp01.js +6 -3
  125. package/utils/math/damp.cjs +28 -0
  126. package/utils/math/damp.js +5 -4
  127. package/utils/math/ease.cjs +88 -0
  128. package/utils/math/ease.d.ts +78 -0
  129. package/utils/math/ease.js +66 -0
  130. package/utils/math/index.cjs +43 -0
  131. package/utils/math/index.d.ts +8 -8
  132. package/utils/math/index.js +17 -8
  133. package/utils/math/inertiaFinalValue.cjs +37 -0
  134. package/utils/math/inertiaFinalValue.js +8 -10
  135. package/utils/math/lerp.cjs +28 -0
  136. package/utils/math/lerp.js +5 -2
  137. package/utils/math/map.cjs +28 -0
  138. package/utils/math/map.js +5 -2
  139. package/utils/math/round.cjs +28 -0
  140. package/utils/math/round.js +5 -3
  141. package/utils/memoize.cjs +43 -0
  142. package/utils/memoize.js +10 -19
  143. package/utils/nextFrame.cjs +38 -0
  144. package/utils/nextFrame.d.ts +4 -3
  145. package/utils/nextFrame.js +13 -10
  146. package/utils/nextMicrotask.cjs +28 -0
  147. package/utils/nextMicrotask.d.ts +8 -0
  148. package/utils/nextMicrotask.js +6 -0
  149. package/utils/nextTick.cjs +30 -0
  150. package/utils/nextTick.d.ts +8 -0
  151. package/utils/nextTick.js +8 -0
  152. package/utils/object/autoBind.cjs +49 -0
  153. package/utils/object/autoBind.js +12 -22
  154. package/utils/object/getAllProperties.cjs +37 -0
  155. package/utils/object/getAllProperties.js +10 -13
  156. package/utils/object/index.cjs +33 -0
  157. package/utils/object/index.d.ts +3 -4
  158. package/utils/object/index.js +8 -4
  159. package/utils/object/isObject.cjs +28 -0
  160. package/utils/object/isObject.js +6 -3
  161. package/utils/scrollTo.cjs +80 -0
  162. package/utils/scrollTo.js +20 -40
  163. package/utils/string/index.cjs +47 -0
  164. package/utils/string/index.d.ts +10 -11
  165. package/utils/string/index.js +22 -11
  166. package/utils/string/withLeadingCharacters.cjs +32 -0
  167. package/utils/string/withLeadingCharacters.js +7 -4
  168. package/utils/string/withLeadingSlash.cjs +32 -0
  169. package/utils/string/withLeadingSlash.js +7 -4
  170. package/utils/string/withTrailingCharacters.cjs +32 -0
  171. package/utils/string/withTrailingCharacters.js +7 -4
  172. package/utils/string/withTrailingSlash.cjs +32 -0
  173. package/utils/string/withTrailingSlash.js +7 -4
  174. package/utils/string/withoutLeadingCharacters.cjs +28 -0
  175. package/utils/string/withoutLeadingCharacters.js +6 -3
  176. package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
  177. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  178. package/utils/string/withoutLeadingSlash.cjs +32 -0
  179. package/utils/string/withoutLeadingSlash.js +7 -4
  180. package/utils/string/withoutTrailingCharacters.cjs +28 -0
  181. package/utils/string/withoutTrailingCharacters.js +6 -3
  182. package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
  183. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  184. package/utils/string/withoutTrailingSlash.cjs +32 -0
  185. package/utils/string/withoutTrailingSlash.js +7 -4
  186. package/utils/throttle.cjs +36 -0
  187. package/utils/throttle.js +9 -9
  188. package/index.modern.js +0 -1
  189. 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,54 @@ 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
57
  return this;
63
58
  }
64
-
65
59
  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();
60
+ const options = { passive: true };
61
+ this.props.target.addEventListener("mousedown", this, options);
62
+ this.props.target.addEventListener("touchstart", this, options);
63
+ this.props.target.addEventListener("dragstart", this, { capture: true });
64
+ this.props.target.addEventListener("click", this, { capture: true });
65
+ const pointer = usePointer();
72
66
  pointer.add(this.id, this.pointerHandler);
73
67
  return this;
74
68
  }
75
-
76
69
  kill() {
77
- this.props.target.removeEventListener('mousemove', this);
78
- this.props.target.removeEventListener('touchmove', this);
79
- var pointer = usePointer();
70
+ this.props.target.removeEventListener("mousedown", this);
71
+ this.props.target.removeEventListener("touchstart", this);
72
+ this.props.target.removeEventListener("dragstart", this);
73
+ this.props.target.removeEventListener("click", this);
74
+ const pointer = usePointer();
80
75
  pointer.remove(this.id);
81
76
  return this;
82
77
  }
83
-
84
78
  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;
79
+ if (event.type === "dragstart") {
80
+ event.preventDefault();
81
+ return;
82
+ }
83
+ if (event.type === "click") {
84
+ if (this.__shouldPreventClick) {
85
+ event.stopImmediatePropagation();
86
+ event.stopPropagation();
87
+ event.preventDefault();
88
+ }
89
+ return;
90
+ }
91
+ const x = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;
92
+ const y = event instanceof MouseEvent ? event.clientY : event.touches[0].clientY;
87
93
  this.start(x, y);
88
94
  }
89
-
90
95
  start(x, y) {
91
96
  this.props.x = x;
92
97
  this.props.y = y;
@@ -102,7 +107,6 @@ class Drag extends Service {
102
107
  this.props.isGrabbing = true;
103
108
  this.trigger(this.props);
104
109
  }
105
-
106
110
  drop() {
107
111
  this.props.isGrabbing = false;
108
112
  this.props.mode = MODES.DROP;
@@ -111,19 +115,17 @@ class Drag extends Service {
111
115
  this.props.final.y = inertiaFinalValue(this.props.y, this.props.delta.y, this.options.dampFactor);
112
116
  this.trigger(this.props);
113
117
  setTimeout(() => {
114
- var raf = useRaf();
118
+ const raf = useRaf();
115
119
  raf.remove(this.id);
116
120
  raf.add(this.id, this.rafHandler);
117
121
  }, 0);
118
122
  }
119
-
120
123
  stop() {
121
124
  useRaf().remove(this.id);
122
125
  this.props.hasInertia = false;
123
126
  this.props.mode = MODES.STOP;
124
127
  this.trigger(this.props);
125
128
  }
126
-
127
129
  rafHandler() {
128
130
  if (!this.props.isGrabbing) {
129
131
  this.props.x += this.props.delta.x;
@@ -132,19 +134,15 @@ class Drag extends Service {
132
134
  this.props.distance.y = this.props.y - this.props.origin.y;
133
135
  this.props.delta.x *= this.options.dampFactor;
134
136
  this.props.delta.y *= this.options.dampFactor;
135
-
136
137
  if (this.props.mode !== MODES.INERTIA) {
137
138
  this.props.mode = MODES.INERTIA;
138
139
  }
139
-
140
140
  this.trigger(this.props);
141
-
142
141
  if (Math.abs(this.props.delta.x) < 0.1 && Math.abs(this.props.delta.y) < 0.1) {
143
142
  this.stop();
144
143
  }
145
144
  }
146
145
  }
147
-
148
146
  pointerHandler(props) {
149
147
  if (this.props.isGrabbing) {
150
148
  this.props.x = props.x;
@@ -155,31 +153,27 @@ class Drag extends Service {
155
153
  this.props.final.y = props.y;
156
154
  this.props.distance.x = this.props.x - this.props.origin.x;
157
155
  this.props.distance.y = this.props.y - this.props.origin.y;
158
-
159
156
  if (this.props.mode !== MODES.DRAG) {
160
157
  this.props.mode = MODES.DRAG;
161
158
  }
162
-
163
159
  this.trigger(this.props);
164
-
165
160
  if (!props.isDown) {
166
161
  this.drop();
167
162
  }
168
163
  }
169
164
  }
170
-
171
165
  updateProps() {
172
166
  return this.props;
173
167
  }
174
-
168
+ get __shouldPreventClick() {
169
+ return Math.abs(this.props.distance.x) > this.options.dragTreshold || Math.abs(this.props.distance.y) > this.options.dragTreshold;
170
+ }
175
171
  }
176
-
177
- var instances = new WeakMap();
178
- export default function useDrag(target, options) {
179
- var drag = instances.get(target);
180
-
172
+ const instances = /* @__PURE__ */ new WeakMap();
173
+ function useDrag(target, options) {
174
+ let drag = instances.get(target);
181
175
  if (!drag) {
182
- var instance = new Drag(target, options);
176
+ const instance = new Drag(target, options);
183
177
  drag = {
184
178
  add: instance.add.bind(instance),
185
179
  remove: instance.remove.bind(instance),
@@ -188,6 +182,8 @@ export default function useDrag(target, options) {
188
182
  };
189
183
  instances.set(target, drag);
190
184
  }
191
-
192
185
  return drag;
193
- }
186
+ }
187
+ export {
188
+ useDrag as default
189
+ };
@@ -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;
@@ -1,3 +1,10 @@
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
8
  export type ServiceInterface<T> = {
2
9
  /**
3
10
  * Remove a function from the resize service by its key.
@@ -16,11 +23,3 @@ export type ServiceInterface<T> = {
16
23
  */
17
24
  props: () => T;
18
25
  };
19
- import useKey from "./key.js";
20
- import usePointer from "./pointer.js";
21
- import useDrag from "./drag.js";
22
- import useLoad from "./load.js";
23
- import useRaf from "./raf.js";
24
- import useResize from "./resize.js";
25
- import useScroll from "./scroll.js";
26
- export { useKey, usePointer, useDrag, useLoad, useRaf, useResize, useScroll };
package/services/index.js CHANGED
@@ -1,8 +1,16 @@
1
- import useDrag from './drag.js';
2
- import useKey from './key.js';
3
- import useLoad from './load.js';
4
- import usePointer from './pointer.js';
5
- import useRaf from './raf.js';
6
- import useResize from './resize.js';
7
- import useScroll from './scroll.js';
8
- export { useKey, usePointer, useDrag, useLoad, useRaf, useResize, useScroll };
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.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;
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
+ };