@studiometa/js-toolkit 2.0.0-beta.9 → 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 (179) hide show
  1. package/Base/index.cjs +285 -0
  2. package/Base/index.d.ts +11 -2
  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 +28 -38
  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/decorators/index.cjs +45 -0
  19. package/decorators/index.d.ts +1 -0
  20. package/decorators/index.js +20 -8
  21. package/decorators/withBreakpointManager.cjs +85 -0
  22. package/decorators/withBreakpointManager.js +18 -39
  23. package/decorators/withBreakpointObserver.cjs +115 -0
  24. package/decorators/withBreakpointObserver.js +44 -86
  25. package/decorators/withDrag.cjs +53 -0
  26. package/decorators/withDrag.js +24 -26
  27. package/decorators/withExtraConfig.cjs +43 -0
  28. package/decorators/withExtraConfig.js +17 -12
  29. package/decorators/withFreezedOptions.cjs +36 -0
  30. package/decorators/withFreezedOptions.d.ts +14 -0
  31. package/decorators/withFreezedOptions.js +14 -0
  32. package/decorators/withIntersectionObserver.cjs +62 -0
  33. package/decorators/withIntersectionObserver.js +29 -32
  34. package/decorators/withMountWhenInView.cjs +69 -0
  35. package/decorators/withMountWhenInView.js +31 -52
  36. package/decorators/withScrolledInView.cjs +114 -0
  37. package/decorators/withScrolledInView.js +35 -39
  38. package/decorators/withVue2.cjs +60 -0
  39. package/decorators/withVue2.js +26 -32
  40. package/helpers/createApp.cjs +52 -0
  41. package/helpers/createApp.d.ts +2 -2
  42. package/helpers/createApp.js +12 -12
  43. package/helpers/importOnInteraction.cjs +52 -0
  44. package/helpers/importOnInteraction.js +17 -18
  45. package/helpers/importWhenIdle.cjs +49 -0
  46. package/helpers/importWhenIdle.js +14 -17
  47. package/helpers/importWhenVisible.cjs +50 -0
  48. package/helpers/importWhenVisible.js +16 -18
  49. package/helpers/index.cjs +35 -0
  50. package/helpers/index.js +10 -4
  51. package/helpers/utils.cjs +35 -0
  52. package/helpers/utils.js +7 -6
  53. package/index.cjs +33 -0
  54. package/index.js +7 -4
  55. package/package.json +14 -4
  56. package/services/Service.cjs +76 -0
  57. package/services/Service.js +19 -32
  58. package/services/drag.cjs +213 -0
  59. package/services/drag.d.ts +1 -0
  60. package/services/drag.js +64 -68
  61. package/services/index.cjs +41 -0
  62. package/services/index.js +16 -7
  63. package/services/key.cjs +104 -0
  64. package/services/key.js +28 -36
  65. package/services/load.cjs +72 -0
  66. package/services/load.js +17 -19
  67. package/services/pointer.cjs +162 -0
  68. package/services/pointer.js +43 -60
  69. package/services/raf.cjs +83 -0
  70. package/services/raf.js +20 -28
  71. package/services/resize.cjs +108 -0
  72. package/services/resize.js +33 -42
  73. package/services/scroll.cjs +131 -0
  74. package/services/scroll.js +26 -35
  75. package/utils/collide/boundingRectToCircle.cjs +34 -0
  76. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  77. package/utils/collide/boundingRectToCircle.js +7 -10
  78. package/utils/collide/collideCircleCircle.cjs +34 -0
  79. package/utils/collide/collideCircleCircle.js +8 -7
  80. package/utils/collide/collideCircleRect.cjs +46 -0
  81. package/utils/collide/collideCircleRect.js +10 -12
  82. package/utils/collide/collidePointCircle.cjs +31 -0
  83. package/utils/collide/collidePointCircle.js +8 -5
  84. package/utils/collide/collidePointRect.cjs +28 -0
  85. package/utils/collide/collidePointRect.js +5 -2
  86. package/utils/collide/collideRectRect.cjs +28 -0
  87. package/utils/collide/collideRectRect.js +5 -2
  88. package/utils/collide/index.cjs +39 -0
  89. package/utils/collide/index.js +14 -6
  90. package/utils/css/classes.cjs +47 -0
  91. package/utils/css/classes.d.ts +10 -9
  92. package/utils/css/classes.js +18 -14
  93. package/utils/css/index.cjs +38 -0
  94. package/utils/css/index.d.ts +2 -2
  95. package/utils/css/index.js +13 -6
  96. package/utils/css/matrix.cjs +30 -0
  97. package/utils/css/matrix.js +7 -5
  98. package/utils/css/styles.cjs +44 -0
  99. package/utils/css/styles.d.ts +6 -18
  100. package/utils/css/styles.js +12 -12
  101. package/utils/css/transition.cjs +120 -0
  102. package/utils/css/transition.d.ts +15 -9
  103. package/utils/css/transition.js +70 -119
  104. package/utils/debounce.cjs +34 -0
  105. package/utils/debounce.js +7 -9
  106. package/utils/focusTrap.cjs +82 -0
  107. package/utils/focusTrap.js +30 -21
  108. package/utils/history.cjs +89 -0
  109. package/utils/history.js +28 -57
  110. package/utils/index.cjs +54 -0
  111. package/utils/index.d.ts +4 -1
  112. package/utils/index.js +32 -11
  113. package/utils/keyCodes.cjs +35 -0
  114. package/utils/keyCodes.js +5 -2
  115. package/utils/math/clamp.cjs +28 -0
  116. package/utils/math/clamp.js +5 -2
  117. package/utils/math/clamp01.cjs +32 -0
  118. package/utils/math/clamp01.js +6 -3
  119. package/utils/math/damp.cjs +28 -0
  120. package/utils/math/damp.js +5 -4
  121. package/utils/math/ease.cjs +88 -0
  122. package/utils/math/ease.js +50 -25
  123. package/utils/math/index.cjs +43 -0
  124. package/utils/math/index.js +17 -8
  125. package/utils/math/inertiaFinalValue.cjs +37 -0
  126. package/utils/math/inertiaFinalValue.js +8 -10
  127. package/utils/math/lerp.cjs +28 -0
  128. package/utils/math/lerp.js +5 -2
  129. package/utils/math/map.cjs +28 -0
  130. package/utils/math/map.js +5 -2
  131. package/utils/math/round.cjs +28 -0
  132. package/utils/math/round.js +5 -3
  133. package/utils/memoize.cjs +43 -0
  134. package/utils/memoize.js +10 -19
  135. package/utils/nextFrame.cjs +38 -0
  136. package/utils/nextFrame.d.ts +4 -3
  137. package/utils/nextFrame.js +13 -10
  138. package/utils/nextMicrotask.cjs +28 -0
  139. package/utils/nextMicrotask.d.ts +8 -0
  140. package/utils/nextMicrotask.js +6 -0
  141. package/utils/nextTick.cjs +30 -0
  142. package/utils/nextTick.d.ts +8 -0
  143. package/utils/nextTick.js +8 -0
  144. package/utils/object/autoBind.cjs +49 -0
  145. package/utils/object/autoBind.js +12 -22
  146. package/utils/object/getAllProperties.cjs +37 -0
  147. package/utils/object/getAllProperties.js +10 -13
  148. package/utils/object/index.cjs +33 -0
  149. package/utils/object/index.js +8 -3
  150. package/utils/object/isObject.cjs +28 -0
  151. package/utils/object/isObject.js +6 -3
  152. package/utils/scrollTo.cjs +80 -0
  153. package/utils/scrollTo.js +20 -40
  154. package/utils/string/index.cjs +47 -0
  155. package/utils/string/index.js +22 -10
  156. package/utils/string/withLeadingCharacters.cjs +32 -0
  157. package/utils/string/withLeadingCharacters.js +7 -4
  158. package/utils/string/withLeadingSlash.cjs +32 -0
  159. package/utils/string/withLeadingSlash.js +7 -4
  160. package/utils/string/withTrailingCharacters.cjs +32 -0
  161. package/utils/string/withTrailingCharacters.js +7 -4
  162. package/utils/string/withTrailingSlash.cjs +32 -0
  163. package/utils/string/withTrailingSlash.js +7 -4
  164. package/utils/string/withoutLeadingCharacters.cjs +28 -0
  165. package/utils/string/withoutLeadingCharacters.js +6 -3
  166. package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
  167. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  168. package/utils/string/withoutLeadingSlash.cjs +32 -0
  169. package/utils/string/withoutLeadingSlash.js +7 -4
  170. package/utils/string/withoutTrailingCharacters.cjs +28 -0
  171. package/utils/string/withoutTrailingCharacters.js +6 -3
  172. package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
  173. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  174. package/utils/string/withoutTrailingSlash.cjs +32 -0
  175. package/utils/string/withoutTrailingSlash.js +7 -4
  176. package/utils/throttle.cjs +36 -0
  177. package/utils/throttle.js +9 -9
  178. package/index.modern.js +0 -1
  179. package/index.umd.js +0 -1
@@ -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
+ };
@@ -0,0 +1,162 @@
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/pointer.js
28
+ var pointer_exports = {};
29
+ __export(pointer_exports, {
30
+ default: () => usePointer
31
+ });
32
+ module.exports = __toCommonJS(pointer_exports);
33
+ var import_Service = __toESM(require("./Service.cjs"), 1);
34
+ function isTouchEvent(event) {
35
+ return typeof TouchEvent !== "undefined" && event instanceof TouchEvent;
36
+ }
37
+ var Pointer = class extends import_Service.default {
38
+ constructor() {
39
+ super(...arguments);
40
+ __publicField(this, "props", {
41
+ event: null,
42
+ isDown: false,
43
+ x: window.innerWidth / 2,
44
+ y: window.innerHeight / 2,
45
+ changed: {
46
+ x: false,
47
+ y: false
48
+ },
49
+ last: {
50
+ x: window.innerWidth / 2,
51
+ y: window.innerHeight / 2
52
+ },
53
+ delta: {
54
+ x: 0,
55
+ y: 0
56
+ },
57
+ progress: {
58
+ x: 0.5,
59
+ y: 0.5
60
+ },
61
+ max: {
62
+ x: window.innerWidth,
63
+ y: window.innerHeight
64
+ }
65
+ });
66
+ __publicField(this, "hasRaf", false);
67
+ }
68
+ init() {
69
+ document.documentElement.addEventListener("mouseenter", this, {
70
+ once: true,
71
+ capture: true
72
+ });
73
+ const options = { passive: true, capture: true };
74
+ document.addEventListener("mousemove", this, options);
75
+ document.addEventListener("touchmove", this, options);
76
+ document.addEventListener("mousedown", this, options);
77
+ document.addEventListener("touchstart", this, options);
78
+ document.addEventListener("mouseup", this, options);
79
+ document.addEventListener("touchend", this, options);
80
+ return this;
81
+ }
82
+ handleEvent(event) {
83
+ switch (event.type) {
84
+ case "mouseenter":
85
+ case "mousemove":
86
+ case "touchmove":
87
+ this.handler(event);
88
+ break;
89
+ case "mousedown":
90
+ case "touchstart":
91
+ this.downHandler();
92
+ break;
93
+ case "mouseup":
94
+ case "touchend":
95
+ this.upHandler();
96
+ break;
97
+ }
98
+ }
99
+ kill() {
100
+ document.removeEventListener("mousemove", this);
101
+ document.removeEventListener("touchmove", this);
102
+ document.removeEventListener("mousedown", this);
103
+ document.removeEventListener("touchstart", this);
104
+ document.removeEventListener("mouseup", this);
105
+ document.removeEventListener("touchend", this);
106
+ return this;
107
+ }
108
+ handler(event) {
109
+ this.updateProps(event);
110
+ this.trigger(this.props);
111
+ }
112
+ downHandler() {
113
+ this.props.isDown = true;
114
+ this.trigger(this.props);
115
+ }
116
+ upHandler() {
117
+ this.props.isDown = false;
118
+ this.trigger(this.props);
119
+ }
120
+ updateProps(event) {
121
+ var _a, _b;
122
+ this.props.event = event;
123
+ const yLast = this.props.y;
124
+ const xLast = this.props.x;
125
+ const y = isTouchEvent(event) ? (_a = event.touches[0]) == null ? void 0 : _a.clientY : event.clientY;
126
+ if (y !== this.props.y) {
127
+ this.props.y = y;
128
+ }
129
+ const x = isTouchEvent(event) ? (_b = event.touches[0]) == null ? void 0 : _b.clientX : event.clientX;
130
+ if (x !== this.props.x) {
131
+ this.props.x = x;
132
+ }
133
+ this.props.changed.x = this.props.x !== xLast;
134
+ this.props.changed.y = this.props.y !== yLast;
135
+ this.props.last.x = xLast;
136
+ this.props.last.y = yLast;
137
+ this.props.delta.x = this.props.x - xLast;
138
+ this.props.delta.y = this.props.y - yLast;
139
+ this.props.max.x = window.innerWidth;
140
+ this.props.max.y = window.innerHeight;
141
+ this.props.progress.x = this.props.x / this.props.max.x;
142
+ this.props.progress.y = this.props.y / this.props.max.y;
143
+ return this.props;
144
+ }
145
+ };
146
+ var instance;
147
+ var pointer;
148
+ function usePointer() {
149
+ if (!pointer) {
150
+ if (!instance) {
151
+ instance = new Pointer();
152
+ }
153
+ pointer = {
154
+ add: instance.add.bind(instance),
155
+ remove: instance.remove.bind(instance),
156
+ has: instance.has.bind(instance),
157
+ props: instance.updateProps.bind(instance)
158
+ };
159
+ }
160
+ return pointer;
161
+ }
162
+ if (module.exports.default) module.exports = module.exports.default;
@@ -1,15 +1,17 @@
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
  function isTouchEvent(event) {
5
- return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;
9
+ return typeof TouchEvent !== "undefined" && event instanceof TouchEvent;
6
10
  }
7
-
8
11
  class Pointer extends Service {
9
12
  constructor() {
10
13
  super(...arguments);
11
-
12
- _defineProperty(this, "props", {
14
+ __publicField(this, "props", {
13
15
  event: null,
14
16
  isDown: false,
15
17
  x: window.innerWidth / 2,
@@ -35,91 +37,73 @@ class Pointer extends Service {
35
37
  y: window.innerHeight
36
38
  }
37
39
  });
38
-
39
- _defineProperty(this, "hasRaf", false);
40
+ __publicField(this, "hasRaf", false);
40
41
  }
41
-
42
42
  init() {
43
- document.documentElement.addEventListener('mouseenter', this, {
43
+ document.documentElement.addEventListener("mouseenter", this, {
44
44
  once: true,
45
45
  capture: true
46
46
  });
47
- var options = {
48
- passive: true,
49
- capture: true
50
- };
51
- document.addEventListener('mousemove', this, options);
52
- document.addEventListener('touchmove', this, options);
53
- document.addEventListener('mousedown', this, options);
54
- document.addEventListener('touchstart', this, options);
55
- document.addEventListener('mouseup', this, options);
56
- document.addEventListener('touchend', this, options);
47
+ const options = { passive: true, capture: true };
48
+ document.addEventListener("mousemove", this, options);
49
+ document.addEventListener("touchmove", this, options);
50
+ document.addEventListener("mousedown", this, options);
51
+ document.addEventListener("touchstart", this, options);
52
+ document.addEventListener("mouseup", this, options);
53
+ document.addEventListener("touchend", this, options);
57
54
  return this;
58
55
  }
59
-
60
56
  handleEvent(event) {
61
57
  switch (event.type) {
62
- case 'mouseenter':
63
- case 'mousemove':
64
- case 'touchmove':
58
+ case "mouseenter":
59
+ case "mousemove":
60
+ case "touchmove":
65
61
  this.handler(event);
66
62
  break;
67
-
68
- case 'mousedown':
69
- case 'touchstart':
63
+ case "mousedown":
64
+ case "touchstart":
70
65
  this.downHandler();
71
66
  break;
72
-
73
- case 'mouseup':
74
- case 'touchend':
67
+ case "mouseup":
68
+ case "touchend":
75
69
  this.upHandler();
76
70
  break;
77
71
  }
78
72
  }
79
-
80
73
  kill() {
81
- document.removeEventListener('mousemove', this);
82
- document.removeEventListener('touchmove', this);
83
- document.removeEventListener('mousedown', this);
84
- document.removeEventListener('touchstart', this);
85
- document.removeEventListener('mouseup', this);
86
- document.removeEventListener('touchend', this);
74
+ document.removeEventListener("mousemove", this);
75
+ document.removeEventListener("touchmove", this);
76
+ document.removeEventListener("mousedown", this);
77
+ document.removeEventListener("touchstart", this);
78
+ document.removeEventListener("mouseup", this);
79
+ document.removeEventListener("touchend", this);
87
80
  return this;
88
81
  }
89
-
90
82
  handler(event) {
91
83
  this.updateProps(event);
92
84
  this.trigger(this.props);
93
85
  }
94
-
95
86
  downHandler() {
96
87
  this.props.isDown = true;
97
88
  this.trigger(this.props);
98
89
  }
99
-
100
90
  upHandler() {
101
91
  this.props.isDown = false;
102
92
  this.trigger(this.props);
103
93
  }
104
-
105
94
  updateProps(event) {
106
- var _event$touches$, _event$touches$2;
107
-
95
+ var _a, _b;
108
96
  this.props.event = event;
109
- var yLast = this.props.y;
110
- var xLast = this.props.x;
111
- var y = isTouchEvent(event) ? (_event$touches$ = event.touches[0]) === null || _event$touches$ === void 0 ? void 0 : _event$touches$.clientY : event.clientY;
112
-
97
+ const yLast = this.props.y;
98
+ const xLast = this.props.x;
99
+ const y = isTouchEvent(event) ? (_a = event.touches[0]) == null ? void 0 : _a.clientY : event.clientY;
113
100
  if (y !== this.props.y) {
114
101
  this.props.y = y;
115
102
  }
116
-
117
- var x = isTouchEvent(event) ? (_event$touches$2 = event.touches[0]) === null || _event$touches$2 === void 0 ? void 0 : _event$touches$2.clientX : event.clientX;
118
-
103
+ const x = isTouchEvent(event) ? (_b = event.touches[0]) == null ? void 0 : _b.clientX : event.clientX;
119
104
  if (x !== this.props.x) {
120
105
  this.props.x = x;
121
106
  }
122
-
123
107
  this.props.changed.x = this.props.x !== xLast;
124
108
  this.props.changed.y = this.props.y !== yLast;
125
109
  this.props.last.x = xLast;
@@ -132,17 +116,14 @@ class Pointer extends Service {
132
116
  this.props.progress.y = this.props.y / this.props.max.y;
133
117
  return this.props;
134
118
  }
135
-
136
119
  }
137
-
138
- var instance;
139
- var pointer;
140
- export default function usePointer() {
120
+ let instance;
121
+ let pointer;
122
+ function usePointer() {
141
123
  if (!pointer) {
142
124
  if (!instance) {
143
125
  instance = new Pointer();
144
126
  }
145
-
146
127
  pointer = {
147
128
  add: instance.add.bind(instance),
148
129
  remove: instance.remove.bind(instance),
@@ -150,6 +131,8 @@ export default function usePointer() {
150
131
  props: instance.updateProps.bind(instance)
151
132
  };
152
133
  }
153
-
154
134
  return pointer;
155
- }
135
+ }
136
+ export {
137
+ usePointer as default
138
+ };