@studiometa/js-toolkit 2.0.0-beta.10 → 2.0.0-beta.14

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 (159) hide show
  1. package/Base/index.cjs +295 -0
  2. package/Base/index.js +88 -174
  3. package/Base/managers/ChildrenManager.cjs +125 -0
  4. package/Base/managers/ChildrenManager.js +29 -55
  5. package/Base/managers/EventsManager.cjs +185 -0
  6. package/Base/managers/EventsManager.js +84 -130
  7. package/Base/managers/OptionsManager.cjs +176 -0
  8. package/Base/managers/OptionsManager.js +46 -88
  9. package/Base/managers/RefsManager.cjs +99 -0
  10. package/Base/managers/RefsManager.js +22 -38
  11. package/Base/managers/ServicesManager.cjs +133 -0
  12. package/Base/managers/ServicesManager.js +31 -65
  13. package/Base/utils.cjs +46 -0
  14. package/Base/utils.js +12 -11
  15. package/decorators/index.cjs +50 -0
  16. package/decorators/index.js +18 -8
  17. package/decorators/withBreakpointManager.cjs +92 -0
  18. package/decorators/withBreakpointManager.js +18 -39
  19. package/decorators/withBreakpointObserver.cjs +117 -0
  20. package/decorators/withBreakpointObserver.js +40 -88
  21. package/decorators/withDrag.cjs +55 -0
  22. package/decorators/withDrag.js +18 -26
  23. package/decorators/withExtraConfig.cjs +45 -0
  24. package/decorators/withExtraConfig.js +11 -12
  25. package/decorators/withIntersectionObserver.cjs +62 -0
  26. package/decorators/withIntersectionObserver.js +23 -32
  27. package/decorators/withMountWhenInView.cjs +69 -0
  28. package/decorators/withMountWhenInView.js +26 -53
  29. package/decorators/withScrolledInView.cjs +113 -0
  30. package/decorators/withScrolledInView.js +50 -63
  31. package/decorators/withVue2.cjs +61 -0
  32. package/decorators/withVue2.js +21 -32
  33. package/helpers/createApp.cjs +57 -0
  34. package/helpers/createApp.js +12 -12
  35. package/helpers/importOnInteraction.cjs +57 -0
  36. package/helpers/importOnInteraction.js +17 -18
  37. package/helpers/importWhenIdle.cjs +53 -0
  38. package/helpers/importWhenIdle.js +13 -17
  39. package/helpers/importWhenVisible.cjs +55 -0
  40. package/helpers/importWhenVisible.js +16 -18
  41. package/helpers/index.cjs +42 -0
  42. package/helpers/index.js +10 -4
  43. package/helpers/utils.cjs +40 -0
  44. package/helpers/utils.js +7 -6
  45. package/index.cjs +39 -0
  46. package/index.js +7 -4
  47. package/package.json +14 -3
  48. package/services/Service.cjs +76 -0
  49. package/services/Service.js +13 -32
  50. package/services/drag.cjs +195 -0
  51. package/services/drag.js +60 -90
  52. package/services/index.cjs +48 -0
  53. package/services/index.js +16 -7
  54. package/services/key.cjs +102 -0
  55. package/services/key.js +34 -52
  56. package/services/load.cjs +71 -0
  57. package/services/load.js +13 -24
  58. package/services/pointer.cjs +160 -0
  59. package/services/pointer.js +60 -87
  60. package/services/raf.cjs +82 -0
  61. package/services/raf.js +16 -33
  62. package/services/resize.cjs +107 -0
  63. package/services/resize.js +31 -49
  64. package/services/scroll.cjs +130 -0
  65. package/services/scroll.js +44 -62
  66. package/utils/collide/boundingRectToCircle.cjs +39 -0
  67. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  68. package/utils/collide/boundingRectToCircle.js +7 -10
  69. package/utils/collide/collideCircleCircle.cjs +39 -0
  70. package/utils/collide/collideCircleCircle.js +8 -7
  71. package/utils/collide/collideCircleRect.cjs +51 -0
  72. package/utils/collide/collideCircleRect.js +10 -12
  73. package/utils/collide/collidePointCircle.cjs +36 -0
  74. package/utils/collide/collidePointCircle.js +8 -5
  75. package/utils/collide/collidePointRect.cjs +33 -0
  76. package/utils/collide/collidePointRect.js +5 -2
  77. package/utils/collide/collideRectRect.cjs +33 -0
  78. package/utils/collide/collideRectRect.js +5 -2
  79. package/utils/collide/index.cjs +46 -0
  80. package/utils/collide/index.js +14 -6
  81. package/utils/css/classes.cjs +49 -0
  82. package/utils/css/classes.js +13 -12
  83. package/utils/css/index.cjs +42 -0
  84. package/utils/css/index.js +10 -6
  85. package/utils/css/matrix.cjs +34 -0
  86. package/utils/css/matrix.js +6 -5
  87. package/utils/css/styles.cjs +52 -0
  88. package/utils/css/styles.js +13 -12
  89. package/utils/css/transition.cjs +122 -0
  90. package/utils/css/transition.js +62 -117
  91. package/utils/debounce.cjs +39 -0
  92. package/utils/debounce.js +7 -9
  93. package/utils/focusTrap.cjs +89 -0
  94. package/utils/focusTrap.js +30 -21
  95. package/utils/history.cjs +96 -0
  96. package/utils/history.js +28 -57
  97. package/utils/index.cjs +58 -0
  98. package/utils/index.d.ts +1 -0
  99. package/utils/index.js +30 -11
  100. package/utils/keyCodes.cjs +40 -0
  101. package/utils/keyCodes.js +5 -2
  102. package/utils/math/clamp.cjs +33 -0
  103. package/utils/math/clamp.js +5 -2
  104. package/utils/math/clamp01.cjs +39 -0
  105. package/utils/math/clamp01.js +6 -3
  106. package/utils/math/damp.cjs +33 -0
  107. package/utils/math/damp.js +5 -4
  108. package/utils/math/ease.cjs +93 -0
  109. package/utils/math/ease.js +50 -25
  110. package/utils/math/index.cjs +49 -0
  111. package/utils/math/index.js +17 -8
  112. package/utils/math/inertiaFinalValue.cjs +42 -0
  113. package/utils/math/inertiaFinalValue.js +8 -10
  114. package/utils/math/lerp.cjs +33 -0
  115. package/utils/math/lerp.js +5 -2
  116. package/utils/math/map.cjs +33 -0
  117. package/utils/math/map.js +5 -2
  118. package/utils/math/round.cjs +33 -0
  119. package/utils/math/round.js +5 -3
  120. package/utils/memoize.cjs +48 -0
  121. package/utils/memoize.js +10 -19
  122. package/utils/nextFrame.cjs +45 -0
  123. package/utils/nextFrame.js +14 -9
  124. package/utils/object/autoBind.cjs +56 -0
  125. package/utils/object/autoBind.js +12 -22
  126. package/utils/object/getAllProperties.cjs +42 -0
  127. package/utils/object/getAllProperties.js +10 -13
  128. package/utils/object/index.cjs +40 -0
  129. package/utils/object/index.js +8 -3
  130. package/utils/object/isObject.cjs +33 -0
  131. package/utils/object/isObject.js +6 -3
  132. package/utils/scrollTo.cjs +87 -0
  133. package/utils/scrollTo.js +20 -40
  134. package/utils/string/index.cjs +54 -0
  135. package/utils/string/index.js +22 -10
  136. package/utils/string/withLeadingCharacters.cjs +39 -0
  137. package/utils/string/withLeadingCharacters.js +7 -4
  138. package/utils/string/withLeadingSlash.cjs +39 -0
  139. package/utils/string/withLeadingSlash.js +7 -4
  140. package/utils/string/withTrailingCharacters.cjs +39 -0
  141. package/utils/string/withTrailingCharacters.js +7 -4
  142. package/utils/string/withTrailingSlash.cjs +39 -0
  143. package/utils/string/withTrailingSlash.js +7 -4
  144. package/utils/string/withoutLeadingCharacters.cjs +33 -0
  145. package/utils/string/withoutLeadingCharacters.js +6 -3
  146. package/utils/string/withoutLeadingCharactersRecursive.cjs +44 -0
  147. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  148. package/utils/string/withoutLeadingSlash.cjs +39 -0
  149. package/utils/string/withoutLeadingSlash.js +7 -4
  150. package/utils/string/withoutTrailingCharacters.cjs +33 -0
  151. package/utils/string/withoutTrailingCharacters.js +6 -3
  152. package/utils/string/withoutTrailingCharactersRecursive.cjs +44 -0
  153. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  154. package/utils/string/withoutTrailingSlash.cjs +39 -0
  155. package/utils/string/withoutTrailingSlash.js +7 -4
  156. package/utils/throttle.cjs +41 -0
  157. package/utils/throttle.js +9 -9
  158. package/index.modern.js +0 -1
  159. package/index.umd.js +0 -1
@@ -0,0 +1,82 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __reExport = (target, module2, copyDefault, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ }
18
+ return target;
19
+ };
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
+ };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
+
29
+ // packages/js-toolkit/services/raf.js
30
+ var raf_exports = {};
31
+ __export(raf_exports, {
32
+ default: () => useRaf
33
+ });
34
+ var import_Service = __toESM(require("./Service.cjs"), 1);
35
+ var import_nextFrame = require("../utils/nextFrame.cjs");
36
+ var Raf = class extends import_Service.default {
37
+ isTicking = false;
38
+ id = 0;
39
+ raf = (0, import_nextFrame.getRaf)();
40
+ cancelRaf = (0, import_nextFrame.getCancelRaf)();
41
+ props = {
42
+ time: performance.now()
43
+ };
44
+ init() {
45
+ this.isTicking = true;
46
+ this.loop();
47
+ }
48
+ loop() {
49
+ this.updateProps();
50
+ this.trigger(this.props);
51
+ if (!this.isTicking) {
52
+ return;
53
+ }
54
+ this.id = this.raf(() => this.loop());
55
+ }
56
+ kill() {
57
+ this.cancelRaf(this.id);
58
+ this.isTicking = false;
59
+ }
60
+ updateProps() {
61
+ this.props.time = window.performance.now();
62
+ return this.props;
63
+ }
64
+ };
65
+ var instance;
66
+ var raf;
67
+ function useRaf() {
68
+ if (!raf) {
69
+ if (!instance) {
70
+ instance = new Raf();
71
+ }
72
+ raf = {
73
+ add: instance.add.bind(instance),
74
+ remove: instance.remove.bind(instance),
75
+ has: instance.has.bind(instance),
76
+ props: instance.updateProps.bind(instance)
77
+ };
78
+ }
79
+ return raf;
80
+ }
81
+ module.exports = __toCommonJS(raf_exports);
82
+ if (module.exports.default) module.exports = module.exports.default;
package/services/raf.js CHANGED
@@ -1,60 +1,41 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import Service from './Service.js';
3
- import { getRaf, getCancelRaf } from '../utils/nextFrame.js';
4
-
1
+ import Service from "./Service.js";
2
+ import { getRaf, getCancelRaf } from "../utils/nextFrame.js";
5
3
  class Raf extends Service {
6
- constructor() {
7
- super(...arguments);
8
-
9
- _defineProperty(this, "isTicking", false);
10
-
11
- _defineProperty(this, "id", 0);
12
-
13
- _defineProperty(this, "raf", getRaf());
14
-
15
- _defineProperty(this, "cancelRaf", getCancelRaf());
16
-
17
- _defineProperty(this, "props", {
18
- time: performance.now()
19
- });
20
- }
21
-
4
+ isTicking = false;
5
+ id = 0;
6
+ raf = getRaf();
7
+ cancelRaf = getCancelRaf();
8
+ props = {
9
+ time: performance.now()
10
+ };
22
11
  init() {
23
12
  this.isTicking = true;
24
13
  this.loop();
25
14
  }
26
-
27
15
  loop() {
28
16
  this.updateProps();
29
17
  this.trigger(this.props);
30
-
31
18
  if (!this.isTicking) {
32
19
  return;
33
20
  }
34
-
35
21
  this.id = this.raf(() => this.loop());
36
22
  }
37
-
38
23
  kill() {
39
24
  this.cancelRaf(this.id);
40
25
  this.isTicking = false;
41
26
  }
42
-
43
27
  updateProps() {
44
28
  this.props.time = window.performance.now();
45
29
  return this.props;
46
30
  }
47
-
48
31
  }
49
-
50
- var instance;
51
- var raf;
52
- export default function useRaf() {
32
+ let instance;
33
+ let raf;
34
+ function useRaf() {
53
35
  if (!raf) {
54
36
  if (!instance) {
55
37
  instance = new Raf();
56
38
  }
57
-
58
39
  raf = {
59
40
  add: instance.add.bind(instance),
60
41
  remove: instance.remove.bind(instance),
@@ -62,6 +43,8 @@ export default function useRaf() {
62
43
  props: instance.updateProps.bind(instance)
63
44
  };
64
45
  }
65
-
66
46
  return raf;
67
- }
47
+ }
48
+ export {
49
+ useRaf as default
50
+ };
@@ -0,0 +1,107 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __reExport = (target, module2, copyDefault, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ }
18
+ return target;
19
+ };
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
+ };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
+
29
+ // packages/js-toolkit/services/resize.js
30
+ var resize_exports = {};
31
+ __export(resize_exports, {
32
+ default: () => useResize
33
+ });
34
+ var import_Service = __toESM(require("./Service.cjs"), 1);
35
+ var import_debounce = __toESM(require("../utils/debounce.cjs"), 1);
36
+ var Resize = class extends import_Service.default {
37
+ props = {
38
+ width: window.innerWidth,
39
+ height: window.innerHeight,
40
+ ratio: window.innerWidth / window.innerHeight,
41
+ orientation: "square"
42
+ };
43
+ handler;
44
+ init() {
45
+ this.handler = (0, import_debounce.default)(() => {
46
+ this.updateProps();
47
+ this.trigger(this.props);
48
+ }).bind(this);
49
+ window.addEventListener("resize", this.handler);
50
+ return this;
51
+ }
52
+ kill() {
53
+ window.removeEventListener("resize", this.handler);
54
+ }
55
+ updateProps() {
56
+ this.props.width = window.innerWidth;
57
+ this.props.height = window.innerHeight;
58
+ this.props.ratio = window.innerWidth / window.innerHeight;
59
+ this.props.orientation = "square";
60
+ if (this.props.ratio > 1) {
61
+ this.props.orientation = "landscape";
62
+ }
63
+ if (this.props.ratio < 1) {
64
+ this.props.orientation = "portrait";
65
+ }
66
+ if (this.breakpointElement) {
67
+ this.props.breakpoint = this.breakpoint;
68
+ this.props.breakpoints = this.breakpoints;
69
+ } else {
70
+ this.props.breakpoint = void 0;
71
+ this.props.breakpoints = void 0;
72
+ }
73
+ return this.props;
74
+ }
75
+ get breakpointElement() {
76
+ return document.querySelector("[data-breakpoint]");
77
+ }
78
+ get breakpoint() {
79
+ return window.getComputedStyle(this.breakpointElement, "::before").getPropertyValue("content").replace(/"/g, "");
80
+ }
81
+ get breakpoints() {
82
+ const breakpoints = window.getComputedStyle(this.breakpointElement, "::after").getPropertyValue("content").replace(/"/g, "");
83
+ return breakpoints.split(",");
84
+ }
85
+ };
86
+ var instance;
87
+ var resize;
88
+ function useResize() {
89
+ if (!resize) {
90
+ if (!instance) {
91
+ instance = new Resize();
92
+ }
93
+ const add = instance.add.bind(instance);
94
+ const remove = instance.remove.bind(instance);
95
+ const has = instance.has.bind(instance);
96
+ const props = instance.updateProps.bind(instance);
97
+ resize = {
98
+ add,
99
+ remove,
100
+ has,
101
+ props
102
+ };
103
+ }
104
+ return resize;
105
+ }
106
+ module.exports = __toCommonJS(resize_exports);
107
+ if (module.exports.default) module.exports = module.exports.default;
@@ -1,86 +1,66 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import Service from './Service.js';
3
- import debounce from '../utils/debounce.js';
4
-
1
+ import Service from "./Service.js";
2
+ import debounce from "../utils/debounce.js";
5
3
  class Resize extends Service {
6
- constructor() {
7
- super(...arguments);
8
-
9
- _defineProperty(this, "props", {
10
- width: window.innerWidth,
11
- height: window.innerHeight,
12
- ratio: window.innerWidth / window.innerHeight,
13
- orientation: 'square'
14
- });
15
-
16
- _defineProperty(this, "handler", void 0);
17
- }
18
-
4
+ props = {
5
+ width: window.innerWidth,
6
+ height: window.innerHeight,
7
+ ratio: window.innerWidth / window.innerHeight,
8
+ orientation: "square"
9
+ };
10
+ handler;
19
11
  init() {
20
12
  this.handler = debounce(() => {
21
13
  this.updateProps();
22
14
  this.trigger(this.props);
23
15
  }).bind(this);
24
- window.addEventListener('resize', this.handler);
16
+ window.addEventListener("resize", this.handler);
25
17
  return this;
26
18
  }
27
-
28
19
  kill() {
29
- window.removeEventListener('resize', this.handler);
20
+ window.removeEventListener("resize", this.handler);
30
21
  }
31
-
32
22
  updateProps() {
33
23
  this.props.width = window.innerWidth;
34
24
  this.props.height = window.innerHeight;
35
25
  this.props.ratio = window.innerWidth / window.innerHeight;
36
- this.props.orientation = 'square';
37
-
26
+ this.props.orientation = "square";
38
27
  if (this.props.ratio > 1) {
39
- this.props.orientation = 'landscape';
28
+ this.props.orientation = "landscape";
40
29
  }
41
-
42
30
  if (this.props.ratio < 1) {
43
- this.props.orientation = 'portrait';
31
+ this.props.orientation = "portrait";
44
32
  }
45
-
46
33
  if (this.breakpointElement) {
47
34
  this.props.breakpoint = this.breakpoint;
48
35
  this.props.breakpoints = this.breakpoints;
49
36
  } else {
50
- this.props.breakpoint = undefined;
51
- this.props.breakpoints = undefined;
37
+ this.props.breakpoint = void 0;
38
+ this.props.breakpoints = void 0;
52
39
  }
53
-
54
40
  return this.props;
55
41
  }
56
-
57
42
  get breakpointElement() {
58
- return document.querySelector('[data-breakpoint]');
43
+ return document.querySelector("[data-breakpoint]");
59
44
  }
60
-
61
45
  get breakpoint() {
62
- return window.getComputedStyle(this.breakpointElement, '::before').getPropertyValue('content').replace(/"/g, '');
46
+ return window.getComputedStyle(this.breakpointElement, "::before").getPropertyValue("content").replace(/"/g, "");
63
47
  }
64
-
65
48
  get breakpoints() {
66
- var breakpoints = window.getComputedStyle(this.breakpointElement, '::after').getPropertyValue('content').replace(/"/g, '');
67
- return breakpoints.split(',');
49
+ const breakpoints = window.getComputedStyle(this.breakpointElement, "::after").getPropertyValue("content").replace(/"/g, "");
50
+ return breakpoints.split(",");
68
51
  }
69
-
70
52
  }
71
-
72
- var instance;
73
- var resize;
74
- export default function useResize() {
53
+ let instance;
54
+ let resize;
55
+ function useResize() {
75
56
  if (!resize) {
76
57
  if (!instance) {
77
58
  instance = new Resize();
78
59
  }
79
-
80
- var add = instance.add.bind(instance);
81
- var remove = instance.remove.bind(instance);
82
- var has = instance.has.bind(instance);
83
- var props = instance.updateProps.bind(instance);
60
+ const add = instance.add.bind(instance);
61
+ const remove = instance.remove.bind(instance);
62
+ const has = instance.has.bind(instance);
63
+ const props = instance.updateProps.bind(instance);
84
64
  resize = {
85
65
  add,
86
66
  remove,
@@ -88,6 +68,8 @@ export default function useResize() {
88
68
  props
89
69
  };
90
70
  }
91
-
92
71
  return resize;
93
- }
72
+ }
73
+ export {
74
+ useResize as default
75
+ };
@@ -0,0 +1,130 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __reExport = (target, module2, copyDefault, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ }
18
+ return target;
19
+ };
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
+ };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
+
29
+ // packages/js-toolkit/services/scroll.js
30
+ var scroll_exports = {};
31
+ __export(scroll_exports, {
32
+ default: () => useScroll
33
+ });
34
+ var import_Service = __toESM(require("./Service.cjs"), 1);
35
+ var import_debounce = __toESM(require("../utils/debounce.cjs"), 1);
36
+ var Scroll = class extends import_Service.default {
37
+ props = {
38
+ x: window.pageXOffset,
39
+ y: window.pageYOffset,
40
+ changed: {
41
+ x: false,
42
+ y: false
43
+ },
44
+ last: {
45
+ x: window.pageXOffset,
46
+ y: window.pageYOffset
47
+ },
48
+ delta: {
49
+ x: 0,
50
+ y: 0
51
+ },
52
+ max: {
53
+ x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
54
+ y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
55
+ },
56
+ progress: {
57
+ x: 0,
58
+ y: 0
59
+ },
60
+ direction: {
61
+ x: "NONE",
62
+ y: "NONE"
63
+ }
64
+ };
65
+ init() {
66
+ this.updateProps();
67
+ document.addEventListener("scroll", this, { passive: true, capture: true });
68
+ return this;
69
+ }
70
+ get debouncedHandler() {
71
+ const debounced = (0, import_debounce.default)(() => {
72
+ this.updateProps();
73
+ this.trigger(this.props);
74
+ }, 100);
75
+ Object.defineProperty(this, "debouncedHandler", {
76
+ value: debounced
77
+ });
78
+ return debounced;
79
+ }
80
+ handleEvent() {
81
+ this.updateProps();
82
+ this.trigger(this.props);
83
+ this.debouncedHandler();
84
+ }
85
+ kill() {
86
+ document.removeEventListener("scroll", this);
87
+ return this;
88
+ }
89
+ updateProps() {
90
+ const yLast = this.props.y;
91
+ const xLast = this.props.x;
92
+ if (window.pageYOffset !== this.props.y) {
93
+ this.props.y = window.pageYOffset;
94
+ }
95
+ if (window.pageXOffset !== this.props.x) {
96
+ this.props.x = window.pageXOffset;
97
+ }
98
+ this.props.changed.x = this.props.x !== xLast;
99
+ this.props.changed.y = this.props.y !== yLast;
100
+ this.props.last.x = xLast;
101
+ this.props.last.y = yLast;
102
+ this.props.delta.x = this.props.x - xLast;
103
+ this.props.delta.y = this.props.y - yLast;
104
+ this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
105
+ this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
106
+ this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
107
+ this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
108
+ this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
109
+ this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
110
+ return this.props;
111
+ }
112
+ };
113
+ var instance;
114
+ var scroll;
115
+ function useScroll() {
116
+ if (!scroll) {
117
+ if (!instance) {
118
+ instance = new Scroll();
119
+ }
120
+ scroll = {
121
+ add: instance.add.bind(instance),
122
+ remove: instance.remove.bind(instance),
123
+ has: instance.has.bind(instance),
124
+ props: instance.updateProps.bind(instance)
125
+ };
126
+ }
127
+ return scroll;
128
+ }
129
+ module.exports = __toCommonJS(scroll_exports);
130
+ if (module.exports.default) module.exports = module.exports.default;
@@ -1,84 +1,67 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import Service from './Service.js';
3
- import debounce from '../utils/debounce.js';
4
-
1
+ import Service from "./Service.js";
2
+ import debounce from "../utils/debounce.js";
5
3
  class Scroll extends Service {
6
- constructor() {
7
- super(...arguments);
8
-
9
- _defineProperty(this, "props", {
4
+ props = {
5
+ x: window.pageXOffset,
6
+ y: window.pageYOffset,
7
+ changed: {
8
+ x: false,
9
+ y: false
10
+ },
11
+ last: {
10
12
  x: window.pageXOffset,
11
- y: window.pageYOffset,
12
- changed: {
13
- x: false,
14
- y: false
15
- },
16
- last: {
17
- x: window.pageXOffset,
18
- y: window.pageYOffset
19
- },
20
- delta: {
21
- x: 0,
22
- y: 0
23
- },
24
- max: {
25
- x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
26
- y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
27
- },
28
- progress: {
29
- x: 0,
30
- y: 0
31
- },
32
- direction: {
33
- x: 'NONE',
34
- y: 'NONE'
35
- }
36
- });
37
- }
38
-
13
+ y: window.pageYOffset
14
+ },
15
+ delta: {
16
+ x: 0,
17
+ y: 0
18
+ },
19
+ max: {
20
+ x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
21
+ y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
22
+ },
23
+ progress: {
24
+ x: 0,
25
+ y: 0
26
+ },
27
+ direction: {
28
+ x: "NONE",
29
+ y: "NONE"
30
+ }
31
+ };
39
32
  init() {
40
33
  this.updateProps();
41
- document.addEventListener('scroll', this, {
42
- passive: true,
43
- capture: true
44
- });
34
+ document.addEventListener("scroll", this, { passive: true, capture: true });
45
35
  return this;
46
36
  }
47
-
48
37
  get debouncedHandler() {
49
- var debounced = debounce(() => {
38
+ const debounced = debounce(() => {
50
39
  this.updateProps();
51
40
  this.trigger(this.props);
52
41
  }, 100);
53
- Object.defineProperty(this, 'debouncedHandler', {
42
+ Object.defineProperty(this, "debouncedHandler", {
54
43
  value: debounced
55
44
  });
56
45
  return debounced;
57
46
  }
58
-
59
47
  handleEvent() {
60
48
  this.updateProps();
61
49
  this.trigger(this.props);
62
50
  this.debouncedHandler();
63
51
  }
64
-
65
52
  kill() {
66
- document.removeEventListener('scroll', this);
53
+ document.removeEventListener("scroll", this);
67
54
  return this;
68
55
  }
69
-
70
56
  updateProps() {
71
- var yLast = this.props.y;
72
- var xLast = this.props.x;
73
-
57
+ const yLast = this.props.y;
58
+ const xLast = this.props.x;
74
59
  if (window.pageYOffset !== this.props.y) {
75
60
  this.props.y = window.pageYOffset;
76
61
  }
77
-
78
62
  if (window.pageXOffset !== this.props.x) {
79
63
  this.props.x = window.pageXOffset;
80
64
  }
81
-
82
65
  this.props.changed.x = this.props.x !== xLast;
83
66
  this.props.changed.y = this.props.y !== yLast;
84
67
  this.props.last.x = xLast;
@@ -89,21 +72,18 @@ class Scroll extends Service {
89
72
  this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
90
73
  this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
91
74
  this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
92
- this.props.direction.x = this.props.x > xLast ? 'RIGHT' : this.props.x < xLast ? 'LEFT' : 'NONE';
93
- this.props.direction.y = this.props.y > yLast ? 'DOWN' : this.props.y < yLast ? 'UP' : 'NONE';
75
+ this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
76
+ this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
94
77
  return this.props;
95
78
  }
96
-
97
79
  }
98
-
99
- var instance;
100
- var scroll;
101
- export default function useScroll() {
80
+ let instance;
81
+ let scroll;
82
+ function useScroll() {
102
83
  if (!scroll) {
103
84
  if (!instance) {
104
85
  instance = new Scroll();
105
86
  }
106
-
107
87
  scroll = {
108
88
  add: instance.add.bind(instance),
109
89
  remove: instance.remove.bind(instance),
@@ -111,6 +91,8 @@ export default function useScroll() {
111
91
  props: instance.updateProps.bind(instance)
112
92
  };
113
93
  }
114
-
115
94
  return scroll;
116
- }
95
+ }
96
+ export {
97
+ useScroll as default
98
+ };