@studiometa/js-toolkit 2.0.0-beta.0 → 2.0.0-beta.12

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 (184) hide show
  1. package/Base/index.cjs +287 -0
  2. package/Base/index.d.ts +27 -1
  3. package/Base/index.js +149 -179
  4. package/Base/managers/ChildrenManager.cjs +122 -0
  5. package/Base/managers/ChildrenManager.js +29 -55
  6. package/Base/managers/EventsManager.cjs +182 -0
  7. package/Base/managers/EventsManager.d.ts +3 -1
  8. package/Base/managers/EventsManager.js +85 -127
  9. package/Base/managers/OptionsManager.cjs +167 -0
  10. package/Base/managers/OptionsManager.d.ts +2 -0
  11. package/Base/managers/OptionsManager.js +46 -88
  12. package/Base/managers/RefsManager.cjs +96 -0
  13. package/Base/managers/RefsManager.d.ts +2 -0
  14. package/Base/managers/RefsManager.js +24 -35
  15. package/Base/managers/ServicesManager.cjs +130 -0
  16. package/Base/managers/ServicesManager.d.ts +29 -4
  17. package/Base/managers/ServicesManager.js +33 -63
  18. package/Base/utils.cjs +43 -0
  19. package/Base/utils.js +12 -11
  20. package/README.md +13 -70
  21. package/decorators/index.cjs +47 -0
  22. package/decorators/index.d.ts +8 -9
  23. package/decorators/index.js +18 -9
  24. package/decorators/withBreakpointManager.cjs +89 -0
  25. package/decorators/withBreakpointManager.js +18 -39
  26. package/decorators/withBreakpointObserver.cjs +114 -0
  27. package/decorators/withBreakpointObserver.js +40 -88
  28. package/decorators/withDrag.cjs +52 -0
  29. package/decorators/withDrag.js +16 -18
  30. package/decorators/withExtraConfig.cjs +42 -0
  31. package/decorators/withExtraConfig.js +11 -12
  32. package/decorators/withIntersectionObserver.cjs +59 -0
  33. package/decorators/withIntersectionObserver.js +23 -31
  34. package/decorators/withMountWhenInView.cjs +66 -0
  35. package/decorators/withMountWhenInView.js +31 -55
  36. package/decorators/withScrolledInView.cjs +110 -0
  37. package/decorators/withScrolledInView.d.ts +4 -1
  38. package/decorators/withScrolledInView.js +77 -73
  39. package/decorators/withVue2.cjs +58 -0
  40. package/decorators/withVue2.js +21 -32
  41. package/helpers/createApp.cjs +54 -0
  42. package/helpers/createApp.js +12 -12
  43. package/helpers/importOnInteraction.cjs +54 -0
  44. package/helpers/importOnInteraction.js +17 -18
  45. package/helpers/importWhenIdle.cjs +50 -0
  46. package/helpers/importWhenIdle.js +13 -17
  47. package/helpers/importWhenVisible.cjs +52 -0
  48. package/helpers/importWhenVisible.js +16 -18
  49. package/helpers/index.cjs +39 -0
  50. package/helpers/index.d.ts +4 -5
  51. package/helpers/index.js +10 -5
  52. package/helpers/utils.cjs +37 -0
  53. package/helpers/utils.js +7 -6
  54. package/index.cjs +36 -0
  55. package/index.d.ts +4 -21
  56. package/index.js +7 -5
  57. package/package.json +14 -3
  58. package/services/Service.cjs +73 -0
  59. package/services/Service.d.ts +22 -17
  60. package/services/Service.js +14 -28
  61. package/services/drag.cjs +192 -0
  62. package/services/drag.d.ts +4 -18
  63. package/services/drag.js +103 -156
  64. package/services/index.cjs +45 -0
  65. package/services/index.d.ts +13 -10
  66. package/services/index.js +16 -8
  67. package/services/key.cjs +99 -0
  68. package/services/key.d.ts +4 -13
  69. package/services/key.js +58 -77
  70. package/services/load.cjs +68 -0
  71. package/services/load.d.ts +3 -13
  72. package/services/load.js +31 -36
  73. package/services/pointer.cjs +157 -0
  74. package/services/pointer.d.ts +4 -13
  75. package/services/pointer.js +91 -121
  76. package/services/raf.cjs +79 -0
  77. package/services/raf.d.ts +3 -13
  78. package/services/raf.js +32 -52
  79. package/services/resize.cjs +104 -0
  80. package/services/resize.d.ts +3 -13
  81. package/services/resize.js +52 -52
  82. package/services/scroll.cjs +127 -0
  83. package/services/scroll.d.ts +3 -13
  84. package/services/scroll.js +75 -89
  85. package/utils/collide/boundingRectToCircle.cjs +36 -0
  86. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  87. package/utils/collide/boundingRectToCircle.js +7 -10
  88. package/utils/collide/collideCircleCircle.cjs +36 -0
  89. package/utils/collide/collideCircleCircle.js +8 -7
  90. package/utils/collide/collideCircleRect.cjs +48 -0
  91. package/utils/collide/collideCircleRect.js +10 -12
  92. package/utils/collide/collidePointCircle.cjs +33 -0
  93. package/utils/collide/collidePointCircle.js +8 -5
  94. package/utils/collide/collidePointRect.cjs +30 -0
  95. package/utils/collide/collidePointRect.js +5 -2
  96. package/utils/collide/collideRectRect.cjs +30 -0
  97. package/utils/collide/collideRectRect.js +5 -2
  98. package/utils/collide/index.cjs +43 -0
  99. package/utils/collide/index.d.ts +6 -7
  100. package/utils/collide/index.js +14 -7
  101. package/utils/css/classes.cjs +46 -0
  102. package/utils/css/classes.js +13 -12
  103. package/utils/css/index.cjs +39 -0
  104. package/utils/css/index.d.ts +4 -5
  105. package/utils/css/index.js +10 -5
  106. package/utils/css/matrix.cjs +31 -0
  107. package/utils/css/matrix.js +6 -5
  108. package/utils/css/styles.cjs +49 -0
  109. package/utils/css/styles.js +13 -12
  110. package/utils/css/transition.cjs +119 -0
  111. package/utils/css/transition.js +62 -117
  112. package/utils/debounce.cjs +36 -0
  113. package/utils/debounce.js +7 -9
  114. package/utils/focusTrap.cjs +86 -0
  115. package/utils/focusTrap.js +30 -21
  116. package/utils/history.cjs +93 -0
  117. package/utils/history.js +28 -57
  118. package/utils/index.cjs +55 -0
  119. package/utils/index.d.ts +12 -35
  120. package/utils/index.js +30 -17
  121. package/utils/keyCodes.cjs +37 -0
  122. package/utils/keyCodes.js +5 -2
  123. package/utils/math/clamp.cjs +30 -0
  124. package/utils/math/clamp.js +5 -2
  125. package/utils/math/clamp01.cjs +36 -0
  126. package/utils/math/clamp01.js +6 -3
  127. package/utils/math/damp.cjs +30 -0
  128. package/utils/math/damp.js +5 -4
  129. package/utils/math/ease.cjs +90 -0
  130. package/utils/math/ease.d.ts +78 -0
  131. package/utils/math/ease.js +66 -0
  132. package/utils/math/index.cjs +46 -0
  133. package/utils/math/index.d.ts +8 -8
  134. package/utils/math/index.js +17 -8
  135. package/utils/math/inertiaFinalValue.cjs +39 -0
  136. package/utils/math/inertiaFinalValue.js +8 -10
  137. package/utils/math/lerp.cjs +30 -0
  138. package/utils/math/lerp.js +5 -2
  139. package/utils/math/map.cjs +30 -0
  140. package/utils/math/map.js +5 -2
  141. package/utils/math/round.cjs +30 -0
  142. package/utils/math/round.js +5 -3
  143. package/utils/memoize.cjs +45 -0
  144. package/utils/memoize.js +10 -19
  145. package/utils/nextFrame.cjs +42 -0
  146. package/utils/nextFrame.js +14 -9
  147. package/utils/object/autoBind.cjs +53 -0
  148. package/utils/object/autoBind.js +12 -22
  149. package/utils/object/getAllProperties.cjs +39 -0
  150. package/utils/object/getAllProperties.js +11 -14
  151. package/utils/object/index.cjs +37 -0
  152. package/utils/object/index.d.ts +3 -4
  153. package/utils/object/index.js +8 -4
  154. package/utils/object/isObject.cjs +30 -0
  155. package/utils/object/isObject.js +6 -3
  156. package/utils/scrollTo.cjs +84 -0
  157. package/utils/scrollTo.js +20 -40
  158. package/utils/string/index.cjs +51 -0
  159. package/utils/string/index.d.ts +10 -11
  160. package/utils/string/index.js +22 -11
  161. package/utils/string/withLeadingCharacters.cjs +36 -0
  162. package/utils/string/withLeadingCharacters.js +7 -4
  163. package/utils/string/withLeadingSlash.cjs +36 -0
  164. package/utils/string/withLeadingSlash.js +7 -4
  165. package/utils/string/withTrailingCharacters.cjs +36 -0
  166. package/utils/string/withTrailingCharacters.js +7 -4
  167. package/utils/string/withTrailingSlash.cjs +36 -0
  168. package/utils/string/withTrailingSlash.js +7 -4
  169. package/utils/string/withoutLeadingCharacters.cjs +30 -0
  170. package/utils/string/withoutLeadingCharacters.js +6 -3
  171. package/utils/string/withoutLeadingCharactersRecursive.cjs +41 -0
  172. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  173. package/utils/string/withoutLeadingSlash.cjs +36 -0
  174. package/utils/string/withoutLeadingSlash.js +7 -4
  175. package/utils/string/withoutTrailingCharacters.cjs +30 -0
  176. package/utils/string/withoutTrailingCharacters.js +6 -3
  177. package/utils/string/withoutTrailingCharactersRecursive.cjs +41 -0
  178. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  179. package/utils/string/withoutTrailingSlash.cjs +36 -0
  180. package/utils/string/withoutTrailingSlash.js +7 -4
  181. package/utils/throttle.cjs +38 -0
  182. package/utils/throttle.js +9 -9
  183. package/index.modern.js +0 -1
  184. package/index.umd.js +0 -1
@@ -1,75 +1,75 @@
1
- import Service from './Service.js';
2
- import debounce from '../utils/debounce.js';
3
-
1
+ import Service from "./Service.js";
2
+ import debounce from "../utils/debounce.js";
4
3
  class Resize extends Service {
4
+ props = {
5
+ width: window.innerWidth,
6
+ height: window.innerHeight,
7
+ ratio: window.innerWidth / window.innerHeight,
8
+ orientation: "square"
9
+ };
10
+ handler;
5
11
  init() {
6
12
  this.handler = debounce(() => {
13
+ this.updateProps();
7
14
  this.trigger(this.props);
8
15
  }).bind(this);
9
- window.addEventListener('resize', this.handler);
16
+ window.addEventListener("resize", this.handler);
10
17
  return this;
11
18
  }
12
-
13
19
  kill() {
14
- window.removeEventListener('resize', this.handler);
15
- return this;
20
+ window.removeEventListener("resize", this.handler);
16
21
  }
17
-
18
- get props() {
19
- var props = {
20
- width: window.innerWidth,
21
- height: window.innerHeight,
22
- ratio: window.innerWidth / window.innerHeight,
23
- orientation: 'square'
24
- };
25
-
26
- if (props.ratio > 1) {
27
- props.orientation = 'landscape';
22
+ updateProps() {
23
+ this.props.width = window.innerWidth;
24
+ this.props.height = window.innerHeight;
25
+ this.props.ratio = window.innerWidth / window.innerHeight;
26
+ this.props.orientation = "square";
27
+ if (this.props.ratio > 1) {
28
+ this.props.orientation = "landscape";
28
29
  }
29
-
30
- if (props.ratio < 1) {
31
- props.orientation = 'portrait';
30
+ if (this.props.ratio < 1) {
31
+ this.props.orientation = "portrait";
32
32
  }
33
-
34
33
  if (this.breakpointElement) {
35
- props.breakpoint = this.breakpoint;
36
- props.breakpoints = this.breakpoints;
34
+ this.props.breakpoint = this.breakpoint;
35
+ this.props.breakpoints = this.breakpoints;
36
+ } else {
37
+ this.props.breakpoint = void 0;
38
+ this.props.breakpoints = void 0;
37
39
  }
38
-
39
- return props;
40
+ return this.props;
40
41
  }
41
-
42
42
  get breakpointElement() {
43
- return document.querySelector('[data-breakpoint]') || null;
43
+ return document.querySelector("[data-breakpoint]");
44
44
  }
45
-
46
45
  get breakpoint() {
47
- return window.getComputedStyle(this.breakpointElement, '::before').getPropertyValue('content').replace(/"/g, '');
46
+ return window.getComputedStyle(this.breakpointElement, "::before").getPropertyValue("content").replace(/"/g, "");
48
47
  }
49
-
50
48
  get breakpoints() {
51
- var breakpoints = window.getComputedStyle(this.breakpointElement, '::after').getPropertyValue('content').replace(/"/g, '');
52
- return breakpoints.split(',');
49
+ const breakpoints = window.getComputedStyle(this.breakpointElement, "::after").getPropertyValue("content").replace(/"/g, "");
50
+ return breakpoints.split(",");
53
51
  }
54
-
55
52
  }
56
-
57
- var resize = null;
58
- export default function useResize() {
53
+ let instance;
54
+ let resize;
55
+ function useResize() {
59
56
  if (!resize) {
60
- resize = new Resize();
57
+ if (!instance) {
58
+ instance = new Resize();
59
+ }
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);
64
+ resize = {
65
+ add,
66
+ remove,
67
+ has,
68
+ props
69
+ };
61
70
  }
62
-
63
- var add = resize.add.bind(resize);
64
- var remove = resize.remove.bind(resize);
65
- var has = resize.has.bind(resize);
66
-
67
- var props = () => resize.props;
68
-
69
- return {
70
- add,
71
- remove,
72
- has,
73
- props
74
- };
75
- }
71
+ return resize;
72
+ }
73
+ export {
74
+ useResize as default
75
+ };
@@ -0,0 +1,127 @@
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
+ var scroll_exports = {};
29
+ __export(scroll_exports, {
30
+ default: () => useScroll
31
+ });
32
+ var import_Service = __toESM(require("./Service.js"), 1);
33
+ var import_debounce = __toESM(require("../utils/debounce.js"), 1);
34
+ class Scroll extends import_Service.default {
35
+ props = {
36
+ x: window.pageXOffset,
37
+ y: window.pageYOffset,
38
+ changed: {
39
+ x: false,
40
+ y: false
41
+ },
42
+ last: {
43
+ x: window.pageXOffset,
44
+ y: window.pageYOffset
45
+ },
46
+ delta: {
47
+ x: 0,
48
+ y: 0
49
+ },
50
+ max: {
51
+ x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
52
+ y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
53
+ },
54
+ progress: {
55
+ x: 0,
56
+ y: 0
57
+ },
58
+ direction: {
59
+ x: "NONE",
60
+ y: "NONE"
61
+ }
62
+ };
63
+ init() {
64
+ this.updateProps();
65
+ document.addEventListener("scroll", this, { passive: true, capture: true });
66
+ return this;
67
+ }
68
+ get debouncedHandler() {
69
+ const debounced = (0, import_debounce.default)(() => {
70
+ this.updateProps();
71
+ this.trigger(this.props);
72
+ }, 100);
73
+ Object.defineProperty(this, "debouncedHandler", {
74
+ value: debounced
75
+ });
76
+ return debounced;
77
+ }
78
+ handleEvent() {
79
+ this.updateProps();
80
+ this.trigger(this.props);
81
+ this.debouncedHandler();
82
+ }
83
+ kill() {
84
+ document.removeEventListener("scroll", this);
85
+ return this;
86
+ }
87
+ updateProps() {
88
+ const yLast = this.props.y;
89
+ const xLast = this.props.x;
90
+ if (window.pageYOffset !== this.props.y) {
91
+ this.props.y = window.pageYOffset;
92
+ }
93
+ if (window.pageXOffset !== this.props.x) {
94
+ this.props.x = window.pageXOffset;
95
+ }
96
+ this.props.changed.x = this.props.x !== xLast;
97
+ this.props.changed.y = this.props.y !== yLast;
98
+ this.props.last.x = xLast;
99
+ this.props.last.y = yLast;
100
+ this.props.delta.x = this.props.x - xLast;
101
+ this.props.delta.y = this.props.y - yLast;
102
+ this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
103
+ this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
104
+ this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
105
+ this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
106
+ this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
107
+ this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
108
+ return this.props;
109
+ }
110
+ }
111
+ let instance;
112
+ let scroll;
113
+ function useScroll() {
114
+ if (!scroll) {
115
+ if (!instance) {
116
+ instance = new Scroll();
117
+ }
118
+ scroll = {
119
+ add: instance.add.bind(instance),
120
+ remove: instance.remove.bind(instance),
121
+ has: instance.has.bind(instance),
122
+ props: instance.updateProps.bind(instance)
123
+ };
124
+ }
125
+ return scroll;
126
+ }
127
+ module.exports = __toCommonJS(scroll_exports);
@@ -9,10 +9,10 @@
9
9
  * props();
10
10
  * ```
11
11
  *
12
- * @return {ServiceInterface & ScrollService}
12
+ * @return {ScrollService}
13
13
  */
14
- export default function useScroll(): ServiceInterface & ScrollService;
15
- export type ServiceInterface = import('./index').ServiceInterface;
14
+ export default function useScroll(): ScrollService;
15
+ export type ScrollService = import('./index').ServiceInterface<ScrollServiceProps>;
16
16
  export type ScrollServiceProps = {
17
17
  x: number;
18
18
  y: number;
@@ -41,13 +41,3 @@ export type ScrollServiceProps = {
41
41
  y: 'UP' | 'DOWN' | 'NONE';
42
42
  };
43
43
  };
44
- export type ScrollService = {
45
- /**
46
- * Add a function to the resize service. The key must be uniq.
47
- */
48
- add: (key: string, callback: (props: ScrollServiceProps) => void) => void;
49
- /**
50
- * Get the current values of the resize service props.
51
- */
52
- props: () => ScrollServiceProps;
53
- };
@@ -1,112 +1,98 @@
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, "y", window.pageYOffset);
10
-
11
- _defineProperty(this, "yLast", window.pageYOffset);
12
-
13
- _defineProperty(this, "x", window.pageXOffset);
14
-
15
- _defineProperty(this, "xLast", window.pageXOffset);
16
- }
17
-
4
+ props = {
5
+ x: window.pageXOffset,
6
+ y: window.pageYOffset,
7
+ changed: {
8
+ x: false,
9
+ y: false
10
+ },
11
+ last: {
12
+ x: window.pageXOffset,
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
+ };
18
32
  init() {
19
- document.addEventListener('scroll', this, {
20
- passive: true,
21
- capture: true
22
- });
33
+ this.updateProps();
34
+ document.addEventListener("scroll", this, { passive: true, capture: true });
23
35
  return this;
24
36
  }
25
-
26
37
  get debouncedHandler() {
27
- var debounced = debounce(() => {
38
+ const debounced = debounce(() => {
39
+ this.updateProps();
28
40
  this.trigger(this.props);
29
- }, 0);
30
- Object.defineProperty(this, 'debouncedHandler', {
41
+ }, 100);
42
+ Object.defineProperty(this, "debouncedHandler", {
31
43
  value: debounced
32
44
  });
33
45
  return debounced;
34
46
  }
35
-
36
47
  handleEvent() {
48
+ this.updateProps();
37
49
  this.trigger(this.props);
38
50
  this.debouncedHandler();
39
51
  }
40
-
41
52
  kill() {
42
- document.removeEventListener('scroll', this);
53
+ document.removeEventListener("scroll", this);
43
54
  return this;
44
55
  }
45
-
46
- get props() {
47
- this.yLast = this.y;
48
- this.xLast = this.x;
49
-
50
- if (window.pageYOffset !== this.y) {
51
- this.y = window.pageYOffset;
56
+ updateProps() {
57
+ const yLast = this.props.y;
58
+ const xLast = this.props.x;
59
+ if (window.pageYOffset !== this.props.y) {
60
+ this.props.y = window.pageYOffset;
52
61
  }
53
-
54
- if (window.pageXOffset !== this.x) {
55
- this.x = window.pageXOffset;
62
+ if (window.pageXOffset !== this.props.x) {
63
+ this.props.x = window.pageXOffset;
56
64
  }
57
-
58
- return {
59
- x: this.x,
60
- y: this.y,
61
- changed: {
62
- x: this.x !== this.xLast,
63
- y: this.y !== this.yLast
64
- },
65
- last: {
66
- x: this.xLast,
67
- y: this.yLast
68
- },
69
- delta: {
70
- x: this.x - this.xLast,
71
- y: this.y - this.yLast
72
- },
73
- progress: {
74
- x: this.max.x === 0 ? 1 : this.x / this.max.x,
75
- y: this.max.y === 0 ? 1 : this.y / this.max.y
76
- },
77
- direction: {
78
- x: this.x > this.xLast ? 'RIGHT' : this.x < this.xLast ? 'LEFT' : 'NONE',
79
- y: this.y > this.yLast ? 'DOWN' : this.y < this.yLast ? 'UP' : 'NONE'
80
- },
81
- max: this.max
82
- };
65
+ this.props.changed.x = this.props.x !== xLast;
66
+ this.props.changed.y = this.props.y !== yLast;
67
+ this.props.last.x = xLast;
68
+ this.props.last.y = yLast;
69
+ this.props.delta.x = this.props.x - xLast;
70
+ this.props.delta.y = this.props.y - yLast;
71
+ this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
72
+ this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
73
+ this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
74
+ this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
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";
77
+ return this.props;
83
78
  }
84
-
85
- get max() {
86
- return {
87
- x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
88
- y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
89
- };
90
- }
91
-
92
79
  }
93
-
94
- var scroll = null;
95
- export default function useScroll() {
80
+ let instance;
81
+ let scroll;
82
+ function useScroll() {
96
83
  if (!scroll) {
97
- scroll = new Scroll();
84
+ if (!instance) {
85
+ instance = new Scroll();
86
+ }
87
+ scroll = {
88
+ add: instance.add.bind(instance),
89
+ remove: instance.remove.bind(instance),
90
+ has: instance.has.bind(instance),
91
+ props: instance.updateProps.bind(instance)
92
+ };
98
93
  }
99
-
100
- var add = scroll.add.bind(scroll);
101
- var remove = scroll.remove.bind(scroll);
102
- var has = scroll.has.bind(scroll);
103
-
104
- var props = () => scroll.props;
105
-
106
- return {
107
- add,
108
- remove,
109
- has,
110
- props
111
- };
112
- }
94
+ return scroll;
95
+ }
96
+ export {
97
+ useScroll as default
98
+ };
@@ -0,0 +1,36 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __reExport = (target, module2, copyDefault, desc) => {
11
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
12
+ for (let key of __getOwnPropNames(module2))
13
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
14
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
15
+ }
16
+ return target;
17
+ };
18
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
19
+ return (module2, temp) => {
20
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
21
+ };
22
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
23
+ var boundingRectToCircle_exports = {};
24
+ __export(boundingRectToCircle_exports, {
25
+ default: () => boundingRectToCircle
26
+ });
27
+ function boundingRectToCircle({ x, y, width, height }, force = false) {
28
+ if (width !== height && !force)
29
+ throw new Error("Initial DOMElement is not a square. Please use the force mode.");
30
+ return {
31
+ x: x + width / 2,
32
+ y: y + height / 2,
33
+ radius: (width + height) / 4
34
+ };
35
+ }
36
+ module.exports = __toCommonJS(boundingRectToCircle_exports);
@@ -11,7 +11,7 @@
11
11
  * @param {Boolean} force Force usage of non-square DOMElements
12
12
  * @return {Circle} Circle object that can be used in collides functions
13
13
  */
14
- export default function collidePointRect({ x, y, width, height }: Partial<DOMRect>, force?: boolean): Circle;
14
+ export default function boundingRectToCircle({ x, y, width, height }: Partial<DOMRect>, force?: boolean): Circle;
15
15
  export type Circle = {
16
16
  /**
17
17
  * Circle's x position
@@ -1,15 +1,12 @@
1
- export default function collidePointRect(_ref) {
2
- var {
3
- x,
4
- y,
5
- width,
6
- height
7
- } = _ref;
8
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
9
- if (width !== height && !force) throw new Error('Initial DOMElement is not a square. Please use the force mode.');
1
+ function boundingRectToCircle({ x, y, width, height }, force = false) {
2
+ if (width !== height && !force)
3
+ throw new Error("Initial DOMElement is not a square. Please use the force mode.");
10
4
  return {
11
5
  x: x + width / 2,
12
6
  y: y + height / 2,
13
7
  radius: (width + height) / 4
14
8
  };
15
- }
9
+ }
10
+ export {
11
+ boundingRectToCircle as default
12
+ };
@@ -0,0 +1,36 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __reExport = (target, module2, copyDefault, desc) => {
11
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
12
+ for (let key of __getOwnPropNames(module2))
13
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
14
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
15
+ }
16
+ return target;
17
+ };
18
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
19
+ return (module2, temp) => {
20
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
21
+ };
22
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
23
+ var collideCircleCircle_exports = {};
24
+ __export(collideCircleCircle_exports, {
25
+ default: () => collideCircleCircle
26
+ });
27
+ function collideCircleCircle(circle1, circle2) {
28
+ const distX = circle1.x - circle2.x;
29
+ const distY = circle1.y - circle2.y;
30
+ const distance = Math.sqrt(distX * distX + distY * distY);
31
+ if (distance <= circle1.radius + circle2.radius) {
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ module.exports = __toCommonJS(collideCircleCircle_exports);
@@ -1,11 +1,12 @@
1
- export default function collideCircleCircle(circle1, circle2) {
2
- var distX = circle1.x - circle2.x;
3
- var distY = circle1.y - circle2.y;
4
- var distance = Math.sqrt(distX * distX + distY * distY);
5
-
1
+ function collideCircleCircle(circle1, circle2) {
2
+ const distX = circle1.x - circle2.x;
3
+ const distY = circle1.y - circle2.y;
4
+ const distance = Math.sqrt(distX * distX + distY * distY);
6
5
  if (distance <= circle1.radius + circle2.radius) {
7
6
  return true;
8
7
  }
9
-
10
8
  return false;
11
- }
9
+ }
10
+ export {
11
+ collideCircleCircle as default
12
+ };
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __reExport = (target, module2, copyDefault, desc) => {
11
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
12
+ for (let key of __getOwnPropNames(module2))
13
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
14
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
15
+ }
16
+ return target;
17
+ };
18
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
19
+ return (module2, temp) => {
20
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
21
+ };
22
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
23
+ var collideCircleRect_exports = {};
24
+ __export(collideCircleRect_exports, {
25
+ default: () => collideCircleRect
26
+ });
27
+ function collideCircleRect(circle, rect) {
28
+ let testX = circle.x;
29
+ let testY = circle.y;
30
+ if (circle.x < rect.x) {
31
+ testX = rect.x;
32
+ } else if (circle.x > rect.x + rect.width) {
33
+ testX = rect.x + rect.width;
34
+ }
35
+ if (circle.y < rect.y) {
36
+ testY = rect.y;
37
+ } else if (circle.y > rect.y + rect.height) {
38
+ testY = rect.y + rect.height;
39
+ }
40
+ const distX = circle.x - testX;
41
+ const distY = circle.y - testY;
42
+ const distance = Math.sqrt(distX * distX + distY * distY);
43
+ if (distance <= circle.radius) {
44
+ return true;
45
+ }
46
+ return false;
47
+ }
48
+ module.exports = __toCommonJS(collideCircleRect_exports);