@studiometa/js-toolkit 2.0.0-beta.1 → 2.0.0-beta.13

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 +294 -0
  2. package/Base/index.d.ts +27 -1
  3. package/Base/index.js +149 -179
  4. package/Base/managers/ChildrenManager.cjs +124 -0
  5. package/Base/managers/ChildrenManager.js +29 -55
  6. package/Base/managers/EventsManager.cjs +184 -0
  7. package/Base/managers/EventsManager.d.ts +3 -1
  8. package/Base/managers/EventsManager.js +85 -127
  9. package/Base/managers/OptionsManager.cjs +175 -0
  10. package/Base/managers/OptionsManager.d.ts +2 -0
  11. package/Base/managers/OptionsManager.js +46 -88
  12. package/Base/managers/RefsManager.cjs +98 -0
  13. package/Base/managers/RefsManager.d.ts +2 -0
  14. package/Base/managers/RefsManager.js +24 -35
  15. package/Base/managers/ServicesManager.cjs +132 -0
  16. package/Base/managers/ServicesManager.d.ts +29 -4
  17. package/Base/managers/ServicesManager.js +33 -63
  18. package/Base/utils.cjs +45 -0
  19. package/Base/utils.js +12 -11
  20. package/README.md +13 -70
  21. package/decorators/index.cjs +49 -0
  22. package/decorators/index.d.ts +8 -9
  23. package/decorators/index.js +18 -9
  24. package/decorators/withBreakpointManager.cjs +91 -0
  25. package/decorators/withBreakpointManager.js +18 -39
  26. package/decorators/withBreakpointObserver.cjs +116 -0
  27. package/decorators/withBreakpointObserver.js +40 -88
  28. package/decorators/withDrag.cjs +54 -0
  29. package/decorators/withDrag.js +16 -18
  30. package/decorators/withExtraConfig.cjs +44 -0
  31. package/decorators/withExtraConfig.js +11 -12
  32. package/decorators/withIntersectionObserver.cjs +61 -0
  33. package/decorators/withIntersectionObserver.js +23 -31
  34. package/decorators/withMountWhenInView.cjs +68 -0
  35. package/decorators/withMountWhenInView.js +31 -55
  36. package/decorators/withScrolledInView.cjs +112 -0
  37. package/decorators/withScrolledInView.d.ts +4 -1
  38. package/decorators/withScrolledInView.js +77 -73
  39. package/decorators/withVue2.cjs +60 -0
  40. package/decorators/withVue2.js +21 -32
  41. package/helpers/createApp.cjs +56 -0
  42. package/helpers/createApp.js +12 -12
  43. package/helpers/importOnInteraction.cjs +56 -0
  44. package/helpers/importOnInteraction.js +17 -18
  45. package/helpers/importWhenIdle.cjs +52 -0
  46. package/helpers/importWhenIdle.js +13 -17
  47. package/helpers/importWhenVisible.cjs +54 -0
  48. package/helpers/importWhenVisible.js +16 -18
  49. package/helpers/index.cjs +41 -0
  50. package/helpers/index.d.ts +4 -5
  51. package/helpers/index.js +10 -5
  52. package/helpers/utils.cjs +39 -0
  53. package/helpers/utils.js +7 -6
  54. package/index.cjs +38 -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 +75 -0
  59. package/services/Service.d.ts +22 -17
  60. package/services/Service.js +14 -28
  61. package/services/drag.cjs +194 -0
  62. package/services/drag.d.ts +4 -18
  63. package/services/drag.js +103 -156
  64. package/services/index.cjs +47 -0
  65. package/services/index.d.ts +13 -10
  66. package/services/index.js +16 -8
  67. package/services/key.cjs +101 -0
  68. package/services/key.d.ts +4 -13
  69. package/services/key.js +58 -77
  70. package/services/load.cjs +70 -0
  71. package/services/load.d.ts +3 -13
  72. package/services/load.js +31 -36
  73. package/services/pointer.cjs +159 -0
  74. package/services/pointer.d.ts +4 -13
  75. package/services/pointer.js +91 -121
  76. package/services/raf.cjs +81 -0
  77. package/services/raf.d.ts +3 -13
  78. package/services/raf.js +32 -52
  79. package/services/resize.cjs +106 -0
  80. package/services/resize.d.ts +3 -13
  81. package/services/resize.js +52 -52
  82. package/services/scroll.cjs +129 -0
  83. package/services/scroll.d.ts +3 -13
  84. package/services/scroll.js +75 -89
  85. package/utils/collide/boundingRectToCircle.cjs +38 -0
  86. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  87. package/utils/collide/boundingRectToCircle.js +7 -10
  88. package/utils/collide/collideCircleCircle.cjs +38 -0
  89. package/utils/collide/collideCircleCircle.js +8 -7
  90. package/utils/collide/collideCircleRect.cjs +50 -0
  91. package/utils/collide/collideCircleRect.js +10 -12
  92. package/utils/collide/collidePointCircle.cjs +35 -0
  93. package/utils/collide/collidePointCircle.js +8 -5
  94. package/utils/collide/collidePointRect.cjs +32 -0
  95. package/utils/collide/collidePointRect.js +5 -2
  96. package/utils/collide/collideRectRect.cjs +32 -0
  97. package/utils/collide/collideRectRect.js +5 -2
  98. package/utils/collide/index.cjs +45 -0
  99. package/utils/collide/index.d.ts +6 -7
  100. package/utils/collide/index.js +14 -7
  101. package/utils/css/classes.cjs +48 -0
  102. package/utils/css/classes.js +13 -12
  103. package/utils/css/index.cjs +41 -0
  104. package/utils/css/index.d.ts +4 -5
  105. package/utils/css/index.js +10 -5
  106. package/utils/css/matrix.cjs +33 -0
  107. package/utils/css/matrix.js +6 -5
  108. package/utils/css/styles.cjs +51 -0
  109. package/utils/css/styles.js +13 -12
  110. package/utils/css/transition.cjs +121 -0
  111. package/utils/css/transition.js +62 -117
  112. package/utils/debounce.cjs +38 -0
  113. package/utils/debounce.js +7 -9
  114. package/utils/focusTrap.cjs +88 -0
  115. package/utils/focusTrap.js +30 -21
  116. package/utils/history.cjs +95 -0
  117. package/utils/history.js +28 -57
  118. package/utils/index.cjs +57 -0
  119. package/utils/index.d.ts +12 -35
  120. package/utils/index.js +30 -17
  121. package/utils/keyCodes.cjs +39 -0
  122. package/utils/keyCodes.js +5 -2
  123. package/utils/math/clamp.cjs +32 -0
  124. package/utils/math/clamp.js +5 -2
  125. package/utils/math/clamp01.cjs +38 -0
  126. package/utils/math/clamp01.js +6 -3
  127. package/utils/math/damp.cjs +32 -0
  128. package/utils/math/damp.js +5 -4
  129. package/utils/math/ease.cjs +92 -0
  130. package/utils/math/ease.d.ts +78 -0
  131. package/utils/math/ease.js +66 -0
  132. package/utils/math/index.cjs +48 -0
  133. package/utils/math/index.d.ts +8 -8
  134. package/utils/math/index.js +17 -8
  135. package/utils/math/inertiaFinalValue.cjs +41 -0
  136. package/utils/math/inertiaFinalValue.js +8 -10
  137. package/utils/math/lerp.cjs +32 -0
  138. package/utils/math/lerp.js +5 -2
  139. package/utils/math/map.cjs +32 -0
  140. package/utils/math/map.js +5 -2
  141. package/utils/math/round.cjs +32 -0
  142. package/utils/math/round.js +5 -3
  143. package/utils/memoize.cjs +47 -0
  144. package/utils/memoize.js +10 -19
  145. package/utils/nextFrame.cjs +44 -0
  146. package/utils/nextFrame.js +14 -9
  147. package/utils/object/autoBind.cjs +55 -0
  148. package/utils/object/autoBind.js +12 -22
  149. package/utils/object/getAllProperties.cjs +41 -0
  150. package/utils/object/getAllProperties.js +11 -14
  151. package/utils/object/index.cjs +39 -0
  152. package/utils/object/index.d.ts +3 -4
  153. package/utils/object/index.js +8 -4
  154. package/utils/object/isObject.cjs +32 -0
  155. package/utils/object/isObject.js +6 -3
  156. package/utils/scrollTo.cjs +86 -0
  157. package/utils/scrollTo.js +20 -40
  158. package/utils/string/index.cjs +53 -0
  159. package/utils/string/index.d.ts +10 -11
  160. package/utils/string/index.js +22 -11
  161. package/utils/string/withLeadingCharacters.cjs +38 -0
  162. package/utils/string/withLeadingCharacters.js +7 -4
  163. package/utils/string/withLeadingSlash.cjs +38 -0
  164. package/utils/string/withLeadingSlash.js +7 -4
  165. package/utils/string/withTrailingCharacters.cjs +38 -0
  166. package/utils/string/withTrailingCharacters.js +7 -4
  167. package/utils/string/withTrailingSlash.cjs +38 -0
  168. package/utils/string/withTrailingSlash.js +7 -4
  169. package/utils/string/withoutLeadingCharacters.cjs +32 -0
  170. package/utils/string/withoutLeadingCharacters.js +6 -3
  171. package/utils/string/withoutLeadingCharactersRecursive.cjs +43 -0
  172. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  173. package/utils/string/withoutLeadingSlash.cjs +38 -0
  174. package/utils/string/withoutLeadingSlash.js +7 -4
  175. package/utils/string/withoutTrailingCharacters.cjs +32 -0
  176. package/utils/string/withoutTrailingCharacters.js +6 -3
  177. package/utils/string/withoutTrailingCharactersRecursive.cjs +43 -0
  178. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  179. package/utils/string/withoutTrailingSlash.cjs +38 -0
  180. package/utils/string/withoutTrailingSlash.js +7 -4
  181. package/utils/throttle.cjs +40 -0
  182. package/utils/throttle.js +9 -9
  183. package/index.modern.js +0 -1
  184. package/index.umd.js +0 -1
@@ -0,0 +1,61 @@
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
+
24
+ // packages/js-toolkit/decorators/withIntersectionObserver.js
25
+ var withIntersectionObserver_exports = {};
26
+ __export(withIntersectionObserver_exports, {
27
+ default: () => withIntersectionObserver
28
+ });
29
+ function createArrayOfNumber(length) {
30
+ return [...new Array(length + 1)].map((val, index) => index / length);
31
+ }
32
+ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: createArrayOfNumber(100) }) {
33
+ return class extends BaseClass {
34
+ static config = {
35
+ ...BaseClass.config || {},
36
+ name: `${BaseClass?.config?.name ?? ""}WithIntersectionObserver`,
37
+ options: {
38
+ ...BaseClass?.config?.options || {},
39
+ intersectionObserver: Object
40
+ },
41
+ emits: ["intersected"]
42
+ };
43
+ constructor(element) {
44
+ super(element);
45
+ if (!this.intersected || typeof this.intersected !== "function") {
46
+ throw new Error("[withIntersectionObserver] The `intersected` method must be defined.");
47
+ }
48
+ this.$observer = new IntersectionObserver((entries) => {
49
+ this.__callMethod("intersected", entries);
50
+ }, { ...defaultOptions, ...this.$options.intersectionObserver || {} });
51
+ this.$on("mounted", () => {
52
+ this.$observer.observe(this.$el);
53
+ });
54
+ this.$on("destroyed", () => {
55
+ this.$observer.unobserve(this.$el);
56
+ });
57
+ return this;
58
+ }
59
+ };
60
+ }
61
+ module.exports = __toCommonJS(withIntersectionObserver_exports);
@@ -1,43 +1,35 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
7
1
  function createArrayOfNumber(length) {
8
2
  return [...new Array(length + 1)].map((val, index) => index / length);
9
3
  }
10
-
11
- export default function withIntersectionObserver(BaseClass) {
12
- var _class, _temp, _BaseClass$config$nam, _BaseClass$config, _BaseClass$config2;
13
-
14
- var defaultOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
15
- threshold: createArrayOfNumber(100)
16
- };
17
- return _temp = _class = class extends BaseClass {
4
+ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: createArrayOfNumber(100) }) {
5
+ return class extends BaseClass {
6
+ static config = {
7
+ ...BaseClass.config || {},
8
+ name: `${BaseClass?.config?.name ?? ""}WithIntersectionObserver`,
9
+ options: {
10
+ ...BaseClass?.config?.options || {},
11
+ intersectionObserver: Object
12
+ },
13
+ emits: ["intersected"]
14
+ };
18
15
  constructor(element) {
19
16
  super(element);
20
-
21
- if (!this.intersected || typeof this.intersected !== 'function') {
22
- throw new Error('[withIntersectionObserver] The `intersected` method must be defined.');
17
+ if (!this.intersected || typeof this.intersected !== "function") {
18
+ throw new Error("[withIntersectionObserver] The `intersected` method must be defined.");
23
19
  }
24
-
25
- this.$observer = new IntersectionObserver(entries => {
26
- this.__callMethod('intersected', entries);
27
- }, _objectSpread(_objectSpread({}, defaultOptions), this.$options.intersectionObserver || {}));
28
- this.$on('mounted', () => {
20
+ this.$observer = new IntersectionObserver((entries) => {
21
+ this.__callMethod("intersected", entries);
22
+ }, { ...defaultOptions, ...this.$options.intersectionObserver || {} });
23
+ this.$on("mounted", () => {
29
24
  this.$observer.observe(this.$el);
30
25
  });
31
- this.$on('destroyed', () => {
26
+ this.$on("destroyed", () => {
32
27
  this.$observer.unobserve(this.$el);
33
28
  });
34
29
  return this;
35
30
  }
36
-
37
- }, _defineProperty(_class, "config", _objectSpread(_objectSpread({}, BaseClass.config || {}), {}, {
38
- name: "".concat((_BaseClass$config$nam = BaseClass === null || BaseClass === void 0 ? void 0 : (_BaseClass$config = BaseClass.config) === null || _BaseClass$config === void 0 ? void 0 : _BaseClass$config.name) !== null && _BaseClass$config$nam !== void 0 ? _BaseClass$config$nam : '', "WithIntersectionObserver"),
39
- options: _objectSpread(_objectSpread({}, (BaseClass === null || BaseClass === void 0 ? void 0 : (_BaseClass$config2 = BaseClass.config) === null || _BaseClass$config2 === void 0 ? void 0 : _BaseClass$config2.options) || {}), {}, {
40
- intersectionObserver: Object
41
- })
42
- })), _temp;
43
- }
31
+ };
32
+ }
33
+ export {
34
+ withIntersectionObserver as default
35
+ };
@@ -0,0 +1,68 @@
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
+
24
+ // packages/js-toolkit/decorators/withMountWhenInView.js
25
+ var withMountWhenInView_exports = {};
26
+ __export(withMountWhenInView_exports, {
27
+ default: () => withMountWhenInView
28
+ });
29
+ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
30
+ return class extends BaseClass {
31
+ static config = {
32
+ ...BaseClass.config || {},
33
+ name: `${BaseClass?.config?.name ?? ""}WithMountWhenInView`,
34
+ options: {
35
+ ...BaseClass?.config?.options || {},
36
+ intersectionObserver: Object
37
+ }
38
+ };
39
+ #isVisible = false;
40
+ #observer;
41
+ constructor(element) {
42
+ super(element);
43
+ this.#observer = new IntersectionObserver((entries) => {
44
+ const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
45
+ if (this.#isVisible !== isVisible) {
46
+ this.#isVisible = isVisible;
47
+ if (isVisible) {
48
+ this.$mount();
49
+ } else {
50
+ setTimeout(() => this.$destroy());
51
+ }
52
+ }
53
+ }, { ...defaultOptions, ...this.$options.intersectionObserver });
54
+ this.#observer.observe(this.$el);
55
+ this.$on("terminated", () => {
56
+ this.#observer.disconnect();
57
+ });
58
+ return this;
59
+ }
60
+ $mount() {
61
+ if (this.#isVisible) {
62
+ super.$mount();
63
+ }
64
+ return this;
65
+ }
66
+ };
67
+ }
68
+ module.exports = __toCommonJS(withMountWhenInView_exports);
@@ -1,66 +1,42 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _classPrivateFieldGet from "@babel/runtime/helpers/classPrivateFieldGet";
3
- import _classPrivateFieldSet from "@babel/runtime/helpers/classPrivateFieldSet";
4
-
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6
-
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
-
9
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
10
-
11
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
12
-
13
- export default function withMountWhenInView(BaseClass) {
14
- var _class, _isVisible, _observer, _temp, _BaseClass$config$nam, _BaseClass$config, _BaseClass$config2;
15
-
16
- var defaultOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
17
- threshold: [0, 1]
18
- };
19
- return _temp = (_isVisible = new WeakMap(), _observer = new WeakMap(), _class = class extends BaseClass {
1
+ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
2
+ return class extends BaseClass {
3
+ static config = {
4
+ ...BaseClass.config || {},
5
+ name: `${BaseClass?.config?.name ?? ""}WithMountWhenInView`,
6
+ options: {
7
+ ...BaseClass?.config?.options || {},
8
+ intersectionObserver: Object
9
+ }
10
+ };
11
+ #isVisible = false;
12
+ #observer;
20
13
  constructor(element) {
21
14
  super(element);
22
-
23
- _classPrivateFieldInitSpec(this, _isVisible, {
24
- writable: true,
25
- value: false
26
- });
27
-
28
- _classPrivateFieldInitSpec(this, _observer, {
29
- writable: true,
30
- value: void 0
31
- });
32
-
33
- _classPrivateFieldSet(this, _observer, new IntersectionObserver(entries => {
34
- var isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
35
-
36
- if (_classPrivateFieldGet(this, _isVisible) !== isVisible) {
37
- _classPrivateFieldSet(this, _isVisible, isVisible);
38
-
39
- var method = isVisible ? '$mount' : '$destroy';
40
- this[method]();
15
+ this.#observer = new IntersectionObserver((entries) => {
16
+ const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
17
+ if (this.#isVisible !== isVisible) {
18
+ this.#isVisible = isVisible;
19
+ if (isVisible) {
20
+ this.$mount();
21
+ } else {
22
+ setTimeout(() => this.$destroy());
23
+ }
41
24
  }
42
- }, _objectSpread(_objectSpread({}, defaultOptions), this.$options.intersectionObserver)));
43
-
44
- _classPrivateFieldGet(this, _observer).observe(this.$el);
45
-
46
- this.$on('terminated', () => {
47
- _classPrivateFieldGet(this, _observer).disconnect();
25
+ }, { ...defaultOptions, ...this.$options.intersectionObserver });
26
+ this.#observer.observe(this.$el);
27
+ this.$on("terminated", () => {
28
+ this.#observer.disconnect();
48
29
  });
49
30
  return this;
50
31
  }
51
-
52
32
  $mount() {
53
- if (_classPrivateFieldGet(this, _isVisible)) {
33
+ if (this.#isVisible) {
54
34
  super.$mount();
55
35
  }
56
-
57
36
  return this;
58
37
  }
59
-
60
- }), _defineProperty(_class, "config", _objectSpread(_objectSpread({}, BaseClass.config || {}), {}, {
61
- name: "".concat((_BaseClass$config$nam = BaseClass === null || BaseClass === void 0 ? void 0 : (_BaseClass$config = BaseClass.config) === null || _BaseClass$config === void 0 ? void 0 : _BaseClass$config.name) !== null && _BaseClass$config$nam !== void 0 ? _BaseClass$config$nam : '', "WithMountWhenInView"),
62
- options: _objectSpread(_objectSpread({}, (BaseClass === null || BaseClass === void 0 ? void 0 : (_BaseClass$config2 = BaseClass.config) === null || _BaseClass$config2 === void 0 ? void 0 : _BaseClass$config2.options) || {}), {}, {
63
- intersectionObserver: Object
64
- })
65
- })), _temp;
66
- }
38
+ };
39
+ }
40
+ export {
41
+ withMountWhenInView as default
42
+ };
@@ -0,0 +1,112 @@
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/decorators/withScrolledInView.js
30
+ var withScrolledInView_exports = {};
31
+ __export(withScrolledInView_exports, {
32
+ default: () => withScrolledInView
33
+ });
34
+ var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
35
+ var import_utils = require("../utils/index.cjs");
36
+ function withScrolledInView(BaseClass, options) {
37
+ return class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
38
+ static config = {
39
+ name: `${BaseClass.config.name}WithMountWhenInView`,
40
+ emits: ["scrolledInView"]
41
+ };
42
+ __props = {
43
+ start: {
44
+ x: 0,
45
+ y: 0
46
+ },
47
+ end: {
48
+ x: 0,
49
+ y: 0
50
+ },
51
+ current: {
52
+ x: 0,
53
+ y: 0
54
+ },
55
+ progress: {
56
+ x: 0,
57
+ y: 0
58
+ },
59
+ dampedProgress: {
60
+ x: 0,
61
+ y: 0
62
+ }
63
+ };
64
+ dampFactor = 0.1;
65
+ dampPrecision = 1e-3;
66
+ mounted() {
67
+ this.__setProps();
68
+ }
69
+ resized() {
70
+ this.__setProps();
71
+ }
72
+ scrolled(props) {
73
+ if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
74
+ this.$services.enable("ticked");
75
+ }
76
+ }
77
+ ticked() {
78
+ this.__props.current.x = (0, import_utils.clamp)(window.pageXOffset, this.__props.start.x, this.__props.end.x);
79
+ this.__props.progress.x = (0, import_utils.clamp01)((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
80
+ this.__props.dampedProgress.x = (0, import_utils.damp)(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
81
+ this.__props.current.y = (0, import_utils.clamp)(window.pageYOffset, this.__props.start.y, this.__props.end.y);
82
+ this.__props.progress.y = (0, import_utils.clamp01)((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
83
+ this.__props.dampedProgress.y = (0, import_utils.damp)(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
84
+ if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
85
+ this.$services.disable("ticked");
86
+ }
87
+ this.__callMethod("scrolledInView", this.__props);
88
+ }
89
+ __setProps() {
90
+ const sizes = this.$el.getBoundingClientRect();
91
+ const yEnd = sizes.top + window.pageYOffset + sizes.height;
92
+ const yStart = yEnd - window.innerHeight - sizes.height;
93
+ const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
94
+ const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
95
+ const xEnd = sizes.left + window.pageXOffset + sizes.width;
96
+ const xStart = xEnd - window.innerWidth - sizes.width;
97
+ const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
98
+ const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
99
+ this.__props.start.x = xStart;
100
+ this.__props.start.y = yStart;
101
+ this.__props.end.x = xEnd;
102
+ this.__props.end.y = yEnd;
103
+ this.__props.current.x = xCurrent;
104
+ this.__props.current.y = yCurrent;
105
+ this.__props.progress.x = xProgress;
106
+ this.__props.progress.y = yProgress;
107
+ this.__props.dampedProgress.x = (0, import_utils.damp)(xProgress, this.__props.dampedProgress.x);
108
+ this.__props.dampedProgress.y = (0, import_utils.damp)(yProgress, this.__props.dampedProgress.y);
109
+ }
110
+ };
111
+ }
112
+ module.exports = __toCommonJS(withScrolledInView_exports);
@@ -1,14 +1,17 @@
1
1
  /**
2
2
  * @typedef {import('../Base').default} Base
3
3
  * @typedef {import('../Base').BaseConstructor} BaseConstructor
4
+ * @typedef {import('../Base').BaseConfig} BaseConfig
4
5
  */
5
6
  /**
6
7
  * Add scrolled in view capabilities to a component.
7
8
  *
8
9
  * @template {BaseConstructor} T
9
10
  * @param {T} BaseClass
11
+ * @param {IntersectionObserverInit} options
10
12
  * @return {T}
11
13
  */
12
- export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T): T;
14
+ export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options: IntersectionObserverInit): T;
13
15
  export type Base = import('../Base').default;
14
16
  export type BaseConstructor = import('../Base').BaseConstructor;
17
+ export type BaseConfig = import('../Base').BaseConfig;
@@ -1,77 +1,81 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import withMountWhenInView from './withMountWhenInView.js';
3
- import { clamp, clamp01 } from '../utils/index.js';
4
- export default function withScrolledInView(BaseClass) {
5
- return class extends withMountWhenInView(BaseClass) {
6
- constructor(element) {
7
- super(element);
8
-
9
- _defineProperty(this, "__props", {
10
- start: {
11
- x: 0,
12
- y: 0
13
- },
14
- end: {
15
- x: 0,
16
- y: 0
17
- },
18
- current: {
19
- x: 0,
20
- y: 0
21
- },
22
- progress: {
23
- x: 0,
24
- y: 0
25
- }
26
- });
27
-
28
- this.$on('mounted', () => this.__setProps());
29
- this.$on('resized', () => this.__setProps());
30
- this.$on('scrolled', _ref => {
31
- var {
32
- detail: [props]
33
- } = _ref;
34
- this.$services.toggle('ticked', props.changed.y || props.changed.x);
35
- });
36
- this.$on('ticked', () => {
37
- this.__props.current.x = clamp(window.pageXOffset, this.__props.start.x, this.__props.end.x);
38
- this.__props.progress.x = clamp01((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
39
- this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
40
- this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
41
-
42
- this.__callMethod('scrolledInView', this.__props);
43
- });
1
+ import withMountWhenInView from "./withMountWhenInView.js";
2
+ import { damp, clamp, clamp01 } from "../utils/index.js";
3
+ function withScrolledInView(BaseClass, options) {
4
+ return class extends withMountWhenInView(BaseClass, options) {
5
+ static config = {
6
+ name: `${BaseClass.config.name}WithMountWhenInView`,
7
+ emits: ["scrolledInView"]
8
+ };
9
+ __props = {
10
+ start: {
11
+ x: 0,
12
+ y: 0
13
+ },
14
+ end: {
15
+ x: 0,
16
+ y: 0
17
+ },
18
+ current: {
19
+ x: 0,
20
+ y: 0
21
+ },
22
+ progress: {
23
+ x: 0,
24
+ y: 0
25
+ },
26
+ dampedProgress: {
27
+ x: 0,
28
+ y: 0
29
+ }
30
+ };
31
+ dampFactor = 0.1;
32
+ dampPrecision = 1e-3;
33
+ mounted() {
34
+ this.__setProps();
35
+ }
36
+ resized() {
37
+ this.__setProps();
38
+ }
39
+ scrolled(props) {
40
+ if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
41
+ this.$services.enable("ticked");
42
+ }
43
+ }
44
+ ticked() {
45
+ this.__props.current.x = clamp(window.pageXOffset, this.__props.start.x, this.__props.end.x);
46
+ this.__props.progress.x = clamp01((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
47
+ this.__props.dampedProgress.x = damp(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
48
+ this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
49
+ this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
50
+ this.__props.dampedProgress.y = damp(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
51
+ if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
52
+ this.$services.disable("ticked");
53
+ }
54
+ this.__callMethod("scrolledInView", this.__props);
44
55
  }
45
-
46
56
  __setProps() {
47
- var sizes = this.$el.getBoundingClientRect();
48
- var yEnd = sizes.top + window.pageYOffset + sizes.height;
49
- var yStart = yEnd - window.innerHeight - sizes.height;
50
- var yCurrent = clamp(window.pageYOffset, yStart, yEnd);
51
- var yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
52
- var xEnd = sizes.left + window.pageXOffset + sizes.width;
53
- var xStart = xEnd - window.innerWidth - sizes.width;
54
- var xCurrent = clamp(window.pageXOffset, xStart, xEnd);
55
- var xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
56
- this.__props = {
57
- start: {
58
- x: xStart,
59
- y: yStart
60
- },
61
- end: {
62
- x: xEnd,
63
- y: yEnd
64
- },
65
- current: {
66
- x: xCurrent,
67
- y: yCurrent
68
- },
69
- progress: {
70
- x: xProgress,
71
- y: yProgress
72
- }
73
- };
57
+ const sizes = this.$el.getBoundingClientRect();
58
+ const yEnd = sizes.top + window.pageYOffset + sizes.height;
59
+ const yStart = yEnd - window.innerHeight - sizes.height;
60
+ const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
61
+ const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
62
+ const xEnd = sizes.left + window.pageXOffset + sizes.width;
63
+ const xStart = xEnd - window.innerWidth - sizes.width;
64
+ const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
65
+ const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
66
+ this.__props.start.x = xStart;
67
+ this.__props.start.y = yStart;
68
+ this.__props.end.x = xEnd;
69
+ this.__props.end.y = yEnd;
70
+ this.__props.current.x = xCurrent;
71
+ this.__props.current.y = yCurrent;
72
+ this.__props.progress.x = xProgress;
73
+ this.__props.progress.y = yProgress;
74
+ this.__props.dampedProgress.x = damp(xProgress, this.__props.dampedProgress.x);
75
+ this.__props.dampedProgress.y = damp(yProgress, this.__props.dampedProgress.y);
74
76
  }
75
-
76
77
  };
77
- }
78
+ }
79
+ export {
80
+ withScrolledInView as default
81
+ };
@@ -0,0 +1,60 @@
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
+
24
+ // packages/js-toolkit/decorators/withVue2.js
25
+ var withVue2_exports = {};
26
+ __export(withVue2_exports, {
27
+ default: () => withVue2_default
28
+ });
29
+ var withVue2_default = (BaseClass, Vue) => {
30
+ return class WithVue2 extends BaseClass {
31
+ static config = {
32
+ ...BaseClass.config || {},
33
+ name: `${BaseClass?.config?.name ?? ""}WithVue`,
34
+ refs: [...BaseClass?.config?.refs ?? [], "vue"]
35
+ };
36
+ $vue;
37
+ static vueConfig;
38
+ constructor(element) {
39
+ super(element);
40
+ const { vueConfig } = this.constructor;
41
+ if (!vueConfig) {
42
+ throw new Error("[withVue] You must define a `vueConfig` object.");
43
+ }
44
+ if (typeof vueConfig.render !== "function") {
45
+ throw new Error("[withVue] You must define a `render` function in vueConfig.");
46
+ }
47
+ this.$vue = new Vue(vueConfig);
48
+ this.$on("mounted", () => {
49
+ if (!(this.$refs.vue instanceof HTMLElement)) {
50
+ throw new Error("[withVue] The `vue` refs must be a single HTMLElement.");
51
+ }
52
+ this.$vue.$mount(this.$refs.vue);
53
+ });
54
+ this.$on("destroyed", () => {
55
+ this.$vue.$destroy();
56
+ });
57
+ }
58
+ };
59
+ };
60
+ module.exports = __toCommonJS(withVue2_exports);