@studiometa/js-toolkit 2.0.0-beta.9 → 2.0.0

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 (238) hide show
  1. package/Base/index.cjs +284 -0
  2. package/Base/index.d.ts +36 -28
  3. package/Base/index.js +113 -197
  4. package/Base/managers/ChildrenManager.cjs +146 -0
  5. package/Base/managers/ChildrenManager.d.ts +11 -3
  6. package/Base/managers/ChildrenManager.js +60 -59
  7. package/Base/managers/EventsManager.cjs +183 -0
  8. package/Base/managers/EventsManager.d.ts +13 -20
  9. package/Base/managers/EventsManager.js +72 -112
  10. package/Base/managers/OptionsManager.cjs +173 -0
  11. package/Base/managers/OptionsManager.d.ts +20 -13
  12. package/Base/managers/OptionsManager.js +60 -91
  13. package/Base/managers/RefsManager.cjs +99 -0
  14. package/Base/managers/RefsManager.d.ts +4 -4
  15. package/Base/managers/RefsManager.js +28 -38
  16. package/Base/managers/ServicesManager.cjs +134 -0
  17. package/Base/managers/ServicesManager.d.ts +14 -8
  18. package/Base/managers/ServicesManager.js +42 -67
  19. package/Base/utils.cjs +41 -0
  20. package/Base/utils.d.ts +4 -4
  21. package/Base/utils.js +12 -11
  22. package/decorators/index.cjs +45 -0
  23. package/decorators/index.d.ts +1 -0
  24. package/decorators/index.js +20 -8
  25. package/decorators/withBreakpointManager.cjs +84 -0
  26. package/decorators/withBreakpointManager.d.ts +2 -2
  27. package/decorators/withBreakpointManager.js +18 -40
  28. package/decorators/withBreakpointObserver.cjs +114 -0
  29. package/decorators/withBreakpointObserver.d.ts +1 -1
  30. package/decorators/withBreakpointObserver.js +45 -88
  31. package/decorators/withDrag.cjs +53 -0
  32. package/decorators/withDrag.d.ts +1 -1
  33. package/decorators/withDrag.js +24 -26
  34. package/decorators/withExtraConfig.cjs +43 -0
  35. package/decorators/withExtraConfig.d.ts +1 -1
  36. package/decorators/withExtraConfig.js +17 -12
  37. package/decorators/withFreezedOptions.cjs +37 -0
  38. package/decorators/withFreezedOptions.d.ts +14 -0
  39. package/decorators/withFreezedOptions.js +15 -0
  40. package/decorators/withIntersectionObserver.cjs +61 -0
  41. package/decorators/withIntersectionObserver.d.ts +1 -1
  42. package/decorators/withIntersectionObserver.js +29 -33
  43. package/decorators/withMountWhenInView.cjs +68 -0
  44. package/decorators/withMountWhenInView.d.ts +1 -1
  45. package/decorators/withMountWhenInView.js +31 -53
  46. package/decorators/withScrolledInView.cjs +114 -0
  47. package/decorators/withScrolledInView.d.ts +1 -1
  48. package/decorators/withScrolledInView.js +35 -39
  49. package/decorators/withVue2.cjs +61 -0
  50. package/decorators/withVue2.js +27 -32
  51. package/helpers/createApp.cjs +52 -0
  52. package/helpers/createApp.d.ts +3 -26
  53. package/helpers/createApp.js +12 -12
  54. package/helpers/getInstanceFromElement.cjs +32 -0
  55. package/helpers/getInstanceFromElement.d.ts +14 -0
  56. package/helpers/getInstanceFromElement.js +10 -0
  57. package/helpers/importOnInteraction.cjs +52 -0
  58. package/helpers/importOnInteraction.d.ts +3 -5
  59. package/helpers/importOnInteraction.js +17 -18
  60. package/helpers/importWhenIdle.cjs +49 -0
  61. package/helpers/importWhenIdle.d.ts +3 -5
  62. package/helpers/importWhenIdle.js +14 -17
  63. package/helpers/importWhenVisible.cjs +50 -0
  64. package/helpers/importWhenVisible.d.ts +4 -6
  65. package/helpers/importWhenVisible.js +16 -18
  66. package/helpers/index.cjs +37 -0
  67. package/helpers/index.d.ts +1 -0
  68. package/helpers/index.js +12 -4
  69. package/helpers/utils.cjs +35 -0
  70. package/helpers/utils.d.ts +3 -4
  71. package/helpers/utils.js +7 -6
  72. package/index.cjs +33 -0
  73. package/index.js +7 -4
  74. package/package.json +14 -4
  75. package/services/Service.cjs +76 -0
  76. package/services/Service.d.ts +9 -9
  77. package/services/Service.js +19 -32
  78. package/services/drag.cjs +212 -0
  79. package/services/drag.d.ts +3 -2
  80. package/services/drag.js +64 -69
  81. package/services/index.cjs +41 -0
  82. package/services/index.js +16 -7
  83. package/services/key.cjs +104 -0
  84. package/services/key.d.ts +1 -1
  85. package/services/key.js +28 -36
  86. package/services/load.cjs +72 -0
  87. package/services/load.d.ts +1 -1
  88. package/services/load.js +17 -19
  89. package/services/pointer.cjs +162 -0
  90. package/services/pointer.d.ts +1 -1
  91. package/services/pointer.js +43 -60
  92. package/services/raf.cjs +83 -0
  93. package/services/raf.d.ts +1 -1
  94. package/services/raf.js +20 -28
  95. package/services/resize.cjs +108 -0
  96. package/services/resize.d.ts +1 -1
  97. package/services/resize.js +33 -42
  98. package/services/scroll.cjs +131 -0
  99. package/services/scroll.d.ts +1 -1
  100. package/services/scroll.js +26 -35
  101. package/utils/collide/boundingRectToCircle.cjs +34 -0
  102. package/utils/collide/boundingRectToCircle.d.ts +6 -6
  103. package/utils/collide/boundingRectToCircle.js +7 -10
  104. package/utils/collide/collideCircleCircle.cjs +34 -0
  105. package/utils/collide/collideCircleCircle.d.ts +4 -4
  106. package/utils/collide/collideCircleCircle.js +8 -7
  107. package/utils/collide/collideCircleRect.cjs +46 -0
  108. package/utils/collide/collideCircleRect.d.ts +8 -8
  109. package/utils/collide/collideCircleRect.js +10 -12
  110. package/utils/collide/collidePointCircle.cjs +31 -0
  111. package/utils/collide/collidePointCircle.d.ts +6 -6
  112. package/utils/collide/collidePointCircle.js +8 -5
  113. package/utils/collide/collidePointRect.cjs +28 -0
  114. package/utils/collide/collidePointRect.d.ts +7 -7
  115. package/utils/collide/collidePointRect.js +5 -2
  116. package/utils/collide/collideRectRect.cjs +28 -0
  117. package/utils/collide/collideRectRect.d.ts +5 -5
  118. package/utils/collide/collideRectRect.js +5 -2
  119. package/utils/collide/index.cjs +39 -0
  120. package/utils/collide/index.js +14 -6
  121. package/utils/css/classes.cjs +47 -0
  122. package/utils/css/classes.d.ts +13 -12
  123. package/utils/css/classes.js +19 -15
  124. package/utils/css/index.cjs +38 -0
  125. package/utils/css/index.d.ts +2 -2
  126. package/utils/css/index.js +13 -6
  127. package/utils/css/matrix.cjs +30 -0
  128. package/utils/css/matrix.d.ts +14 -15
  129. package/utils/css/matrix.js +7 -5
  130. package/utils/css/styles.cjs +44 -0
  131. package/utils/css/styles.d.ts +8 -20
  132. package/utils/css/styles.js +12 -12
  133. package/utils/css/transition.cjs +120 -0
  134. package/utils/css/transition.d.ts +15 -9
  135. package/utils/css/transition.js +70 -119
  136. package/utils/debounce.cjs +34 -0
  137. package/utils/debounce.d.ts +4 -4
  138. package/utils/debounce.js +7 -9
  139. package/utils/focusTrap.cjs +82 -0
  140. package/utils/focusTrap.d.ts +1 -0
  141. package/utils/focusTrap.js +31 -22
  142. package/utils/history.cjs +89 -0
  143. package/utils/history.d.ts +13 -11
  144. package/utils/history.js +28 -57
  145. package/utils/index.cjs +54 -0
  146. package/utils/index.d.ts +4 -1
  147. package/utils/index.js +32 -11
  148. package/utils/keyCodes.cjs +35 -0
  149. package/utils/keyCodes.js +5 -2
  150. package/utils/math/clamp.cjs +28 -0
  151. package/utils/math/clamp.d.ts +1 -1
  152. package/utils/math/clamp.js +5 -2
  153. package/utils/math/clamp01.cjs +32 -0
  154. package/utils/math/clamp01.d.ts +1 -1
  155. package/utils/math/clamp01.js +6 -3
  156. package/utils/math/damp.cjs +28 -0
  157. package/utils/math/damp.d.ts +6 -6
  158. package/utils/math/damp.js +5 -4
  159. package/utils/math/ease.cjs +88 -0
  160. package/utils/math/ease.d.ts +7 -7
  161. package/utils/math/ease.js +50 -25
  162. package/utils/math/index.cjs +43 -0
  163. package/utils/math/index.js +17 -8
  164. package/utils/math/inertiaFinalValue.cjs +37 -0
  165. package/utils/math/inertiaFinalValue.d.ts +5 -5
  166. package/utils/math/inertiaFinalValue.js +8 -10
  167. package/utils/math/lerp.cjs +28 -0
  168. package/utils/math/lerp.d.ts +4 -4
  169. package/utils/math/lerp.js +5 -2
  170. package/utils/math/map.cjs +28 -0
  171. package/utils/math/map.d.ts +6 -6
  172. package/utils/math/map.js +5 -2
  173. package/utils/math/round.cjs +28 -0
  174. package/utils/math/round.d.ts +4 -4
  175. package/utils/math/round.js +5 -3
  176. package/utils/memoize.cjs +43 -0
  177. package/utils/memoize.d.ts +1 -1
  178. package/utils/memoize.js +10 -19
  179. package/utils/nextFrame.cjs +38 -0
  180. package/utils/nextFrame.d.ts +6 -6
  181. package/utils/nextFrame.js +13 -10
  182. package/utils/nextMicrotask.cjs +28 -0
  183. package/utils/nextMicrotask.d.ts +8 -0
  184. package/utils/nextMicrotask.js +6 -0
  185. package/utils/nextTick.cjs +30 -0
  186. package/utils/nextTick.d.ts +8 -0
  187. package/utils/nextTick.js +8 -0
  188. package/utils/object/autoBind.cjs +49 -0
  189. package/utils/object/autoBind.d.ts +3 -3
  190. package/utils/object/autoBind.js +12 -22
  191. package/utils/object/getAllProperties.cjs +37 -0
  192. package/utils/object/getAllProperties.d.ts +3 -3
  193. package/utils/object/getAllProperties.js +10 -13
  194. package/utils/object/index.cjs +33 -0
  195. package/utils/object/index.js +8 -3
  196. package/utils/object/isObject.cjs +28 -0
  197. package/utils/object/isObject.d.ts +1 -1
  198. package/utils/object/isObject.js +6 -3
  199. package/utils/scrollTo.cjs +80 -0
  200. package/utils/scrollTo.d.ts +1 -1
  201. package/utils/scrollTo.js +20 -40
  202. package/utils/string/index.cjs +47 -0
  203. package/utils/string/index.js +22 -10
  204. package/utils/string/withLeadingCharacters.cjs +32 -0
  205. package/utils/string/withLeadingCharacters.d.ts +3 -2
  206. package/utils/string/withLeadingCharacters.js +7 -4
  207. package/utils/string/withLeadingSlash.cjs +32 -0
  208. package/utils/string/withLeadingSlash.d.ts +1 -1
  209. package/utils/string/withLeadingSlash.js +7 -4
  210. package/utils/string/withTrailingCharacters.cjs +32 -0
  211. package/utils/string/withTrailingCharacters.d.ts +3 -2
  212. package/utils/string/withTrailingCharacters.js +7 -4
  213. package/utils/string/withTrailingSlash.cjs +32 -0
  214. package/utils/string/withTrailingSlash.d.ts +1 -1
  215. package/utils/string/withTrailingSlash.js +7 -4
  216. package/utils/string/withoutLeadingCharacters.cjs +28 -0
  217. package/utils/string/withoutLeadingCharacters.d.ts +3 -2
  218. package/utils/string/withoutLeadingCharacters.js +6 -3
  219. package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
  220. package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
  221. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  222. package/utils/string/withoutLeadingSlash.cjs +32 -0
  223. package/utils/string/withoutLeadingSlash.d.ts +1 -1
  224. package/utils/string/withoutLeadingSlash.js +7 -4
  225. package/utils/string/withoutTrailingCharacters.cjs +28 -0
  226. package/utils/string/withoutTrailingCharacters.d.ts +3 -2
  227. package/utils/string/withoutTrailingCharacters.js +6 -3
  228. package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
  229. package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
  230. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  231. package/utils/string/withoutTrailingSlash.cjs +32 -0
  232. package/utils/string/withoutTrailingSlash.d.ts +1 -1
  233. package/utils/string/withoutTrailingSlash.js +7 -4
  234. package/utils/throttle.cjs +36 -0
  235. package/utils/throttle.d.ts +3 -3
  236. package/utils/throttle.js +9 -9
  237. package/index.modern.js +0 -1
  238. package/index.umd.js +0 -1
@@ -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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
23
+
24
+ // packages/js-toolkit/decorators/withMountWhenInView.js
25
+ var withMountWhenInView_exports = {};
26
+ __export(withMountWhenInView_exports, {
27
+ default: () => withMountWhenInView
28
+ });
29
+ module.exports = __toCommonJS(withMountWhenInView_exports);
30
+ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
31
+ var _a, _b;
32
+ return _b = class extends BaseClass {
33
+ constructor(element) {
34
+ super(element);
35
+ __publicField(this, "__isVisible", false);
36
+ __publicField(this, "__observer");
37
+ this.__observer = new IntersectionObserver((entries) => {
38
+ const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
39
+ if (this.__isVisible !== isVisible) {
40
+ this.__isVisible = isVisible;
41
+ if (isVisible) {
42
+ this.$mount();
43
+ } else {
44
+ setTimeout(() => this.$destroy());
45
+ }
46
+ }
47
+ }, { ...defaultOptions, ...this.$options.intersectionObserver });
48
+ this.__observer.observe(this.$el);
49
+ this.$on("terminated", () => {
50
+ this.__observer.disconnect();
51
+ });
52
+ }
53
+ $mount() {
54
+ if (this.__isVisible) {
55
+ super.$mount();
56
+ }
57
+ return this;
58
+ }
59
+ }, __publicField(_b, "config", {
60
+ ...BaseClass.config,
61
+ name: `${BaseClass.config.name}WithMountWhenInView`,
62
+ options: {
63
+ ...((_a = BaseClass.config) == null ? void 0 : _a.options) || {},
64
+ intersectionObserver: Object
65
+ }
66
+ }), _b;
67
+ }
68
+ if (module.exports.default) module.exports = module.exports.default;
@@ -18,7 +18,7 @@
18
18
  * @template {BaseConstructor} T
19
19
  * @param {T} BaseClass The Base class to extend.
20
20
  * @param {IntersectionObserverInit} [defaultOptions] The options for the IntersectionObserver instance.
21
- * @return {T}
21
+ * @returns {T}
22
22
  */
23
23
  export default function withMountWhenInView<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: IntersectionObserverInit): T;
24
24
  export type Base = import('../Base').default;
@@ -1,69 +1,47 @@
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); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
8
+ var _a, _b;
9
+ return _b = class extends BaseClass {
20
10
  constructor(element) {
21
11
  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
-
12
+ __publicField(this, "__isVisible", false);
13
+ __publicField(this, "__observer");
14
+ this.__observer = new IntersectionObserver((entries) => {
15
+ const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
16
+ if (this.__isVisible !== isVisible) {
17
+ this.__isVisible = isVisible;
39
18
  if (isVisible) {
40
19
  this.$mount();
41
20
  } else {
42
21
  setTimeout(() => this.$destroy());
43
22
  }
44
23
  }
45
- }, _objectSpread(_objectSpread({}, defaultOptions), this.$options.intersectionObserver)));
46
-
47
- _classPrivateFieldGet(this, _observer).observe(this.$el);
48
-
49
- this.$on('terminated', () => {
50
- _classPrivateFieldGet(this, _observer).disconnect();
24
+ }, { ...defaultOptions, ...this.$options.intersectionObserver });
25
+ this.__observer.observe(this.$el);
26
+ this.$on("terminated", () => {
27
+ this.__observer.disconnect();
51
28
  });
52
- return this;
53
29
  }
54
-
55
30
  $mount() {
56
- if (_classPrivateFieldGet(this, _isVisible)) {
31
+ if (this.__isVisible) {
57
32
  super.$mount();
58
33
  }
59
-
60
34
  return this;
61
35
  }
62
-
63
- }), _defineProperty(_class, "config", _objectSpread(_objectSpread({}, BaseClass.config || {}), {}, {
64
- 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"),
65
- options: _objectSpread(_objectSpread({}, (BaseClass === null || BaseClass === void 0 ? void 0 : (_BaseClass$config2 = BaseClass.config) === null || _BaseClass$config2 === void 0 ? void 0 : _BaseClass$config2.options) || {}), {}, {
36
+ }, __publicField(_b, "config", {
37
+ ...BaseClass.config,
38
+ name: `${BaseClass.config.name}WithMountWhenInView`,
39
+ options: {
40
+ ...((_a = BaseClass.config) == null ? void 0 : _a.options) || {},
66
41
  intersectionObserver: Object
67
- })
68
- })), _temp;
69
- }
42
+ }
43
+ }), _b;
44
+ }
45
+ export {
46
+ withMountWhenInView as default
47
+ };
@@ -0,0 +1,114 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __publicField = (obj, key, value) => {
23
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
+ return value;
25
+ };
26
+
27
+ // packages/js-toolkit/decorators/withScrolledInView.js
28
+ var withScrolledInView_exports = {};
29
+ __export(withScrolledInView_exports, {
30
+ default: () => withScrolledInView
31
+ });
32
+ module.exports = __toCommonJS(withScrolledInView_exports);
33
+ var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
34
+ var import_utils = require("../utils/index.cjs");
35
+ function withScrolledInView(BaseClass, options) {
36
+ var _a;
37
+ return _a = class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
38
+ constructor() {
39
+ super(...arguments);
40
+ __publicField(this, "__props", {
41
+ start: {
42
+ x: 0,
43
+ y: 0
44
+ },
45
+ end: {
46
+ x: 0,
47
+ y: 0
48
+ },
49
+ current: {
50
+ x: 0,
51
+ y: 0
52
+ },
53
+ progress: {
54
+ x: 0,
55
+ y: 0
56
+ },
57
+ dampedProgress: {
58
+ x: 0,
59
+ y: 0
60
+ }
61
+ });
62
+ __publicField(this, "dampFactor", 0.1);
63
+ __publicField(this, "dampPrecision", 1e-3);
64
+ }
65
+ mounted() {
66
+ this.__setProps();
67
+ }
68
+ resized() {
69
+ this.__setProps();
70
+ }
71
+ scrolled(props) {
72
+ if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
73
+ this.$services.enable("ticked");
74
+ }
75
+ }
76
+ ticked() {
77
+ this.__props.current.x = (0, import_utils.clamp)(window.pageXOffset, this.__props.start.x, this.__props.end.x);
78
+ this.__props.progress.x = (0, import_utils.clamp01)((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
79
+ this.__props.dampedProgress.x = (0, import_utils.damp)(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
80
+ this.__props.current.y = (0, import_utils.clamp)(window.pageYOffset, this.__props.start.y, this.__props.end.y);
81
+ this.__props.progress.y = (0, import_utils.clamp01)((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
82
+ this.__props.dampedProgress.y = (0, import_utils.damp)(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
83
+ if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
84
+ this.$services.disable("ticked");
85
+ }
86
+ this.__callMethod("scrolledInView", this.__props);
87
+ }
88
+ __setProps() {
89
+ const sizes = this.$el.getBoundingClientRect();
90
+ const yEnd = sizes.top + window.pageYOffset + sizes.height;
91
+ const yStart = yEnd - window.innerHeight - sizes.height;
92
+ const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
93
+ const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
94
+ const xEnd = sizes.left + window.pageXOffset + sizes.width;
95
+ const xStart = xEnd - window.innerWidth - sizes.width;
96
+ const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
97
+ const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
98
+ this.__props.start.x = xStart;
99
+ this.__props.start.y = yStart;
100
+ this.__props.end.x = xEnd;
101
+ this.__props.end.y = yEnd;
102
+ this.__props.current.x = xCurrent;
103
+ this.__props.current.y = yCurrent;
104
+ this.__props.progress.x = xProgress;
105
+ this.__props.progress.y = yProgress;
106
+ this.__props.dampedProgress.x = (0, import_utils.damp)(xProgress, this.__props.dampedProgress.x);
107
+ this.__props.dampedProgress.y = (0, import_utils.damp)(yProgress, this.__props.dampedProgress.y);
108
+ }
109
+ }, __publicField(_a, "config", {
110
+ name: `${BaseClass.config.name}WithMountWhenInView`,
111
+ emits: ["scrolledInView"]
112
+ }), _a;
113
+ }
114
+ if (module.exports.default) module.exports = module.exports.default;
@@ -9,7 +9,7 @@
9
9
  * @template {BaseConstructor} T
10
10
  * @param {T} BaseClass
11
11
  * @param {IntersectionObserverInit} options
12
- * @return {T}
12
+ * @returns {T}
13
13
  */
14
14
  export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options: IntersectionObserverInit): T;
15
15
  export type Base = import('../Base').default;
@@ -1,14 +1,17 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import withMountWhenInView from './withMountWhenInView.js';
3
- import { damp, clamp, clamp01 } from '../utils/index.js';
4
- export default function withScrolledInView(BaseClass, options) {
5
- var _class, _temp;
6
-
7
- return _temp = _class = class extends withMountWhenInView(BaseClass, options) {
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import withMountWhenInView from "./withMountWhenInView.js";
8
+ import { damp, clamp, clamp01 } from "../utils/index.js";
9
+ function withScrolledInView(BaseClass, options) {
10
+ var _a;
11
+ return _a = class extends withMountWhenInView(BaseClass, options) {
8
12
  constructor() {
9
13
  super(...arguments);
10
-
11
- _defineProperty(this, "__props", {
14
+ __publicField(this, "__props", {
12
15
  start: {
13
16
  x: 0,
14
17
  y: 0
@@ -30,26 +33,20 @@ export default function withScrolledInView(BaseClass, options) {
30
33
  y: 0
31
34
  }
32
35
  });
33
-
34
- _defineProperty(this, "dampFactor", 0.1);
35
-
36
- _defineProperty(this, "dampPrecision", 0.001);
36
+ __publicField(this, "dampFactor", 0.1);
37
+ __publicField(this, "dampPrecision", 1e-3);
37
38
  }
38
-
39
39
  mounted() {
40
40
  this.__setProps();
41
41
  }
42
-
43
42
  resized() {
44
43
  this.__setProps();
45
44
  }
46
-
47
45
  scrolled(props) {
48
- if (!this.$services.has('ticked') && props.changed.y || props.changed.x) {
49
- this.$services.enable('ticked');
46
+ if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
47
+ this.$services.enable("ticked");
50
48
  }
51
49
  }
52
-
53
50
  ticked() {
54
51
  this.__props.current.x = clamp(window.pageXOffset, this.__props.start.x, this.__props.end.x);
55
52
  this.__props.progress.x = clamp01((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
@@ -57,24 +54,21 @@ export default function withScrolledInView(BaseClass, options) {
57
54
  this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
58
55
  this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
59
56
  this.__props.dampedProgress.y = damp(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
60
-
61
57
  if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
62
- this.$services.disable('ticked');
58
+ this.$services.disable("ticked");
63
59
  }
64
-
65
- this.__callMethod('scrolledInView', this.__props);
60
+ this.__callMethod("scrolledInView", this.__props);
66
61
  }
67
-
68
62
  __setProps() {
69
- var sizes = this.$el.getBoundingClientRect();
70
- var yEnd = sizes.top + window.pageYOffset + sizes.height;
71
- var yStart = yEnd - window.innerHeight - sizes.height;
72
- var yCurrent = clamp(window.pageYOffset, yStart, yEnd);
73
- var yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
74
- var xEnd = sizes.left + window.pageXOffset + sizes.width;
75
- var xStart = xEnd - window.innerWidth - sizes.width;
76
- var xCurrent = clamp(window.pageXOffset, xStart, xEnd);
77
- var xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
63
+ const sizes = this.$el.getBoundingClientRect();
64
+ const yEnd = sizes.top + window.pageYOffset + sizes.height;
65
+ const yStart = yEnd - window.innerHeight - sizes.height;
66
+ const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
67
+ const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
68
+ const xEnd = sizes.left + window.pageXOffset + sizes.width;
69
+ const xStart = xEnd - window.innerWidth - sizes.width;
70
+ const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
71
+ const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
78
72
  this.__props.start.x = xStart;
79
73
  this.__props.start.y = yStart;
80
74
  this.__props.end.x = xEnd;
@@ -86,9 +80,11 @@ export default function withScrolledInView(BaseClass, options) {
86
80
  this.__props.dampedProgress.x = damp(xProgress, this.__props.dampedProgress.x);
87
81
  this.__props.dampedProgress.y = damp(yProgress, this.__props.dampedProgress.y);
88
82
  }
89
-
90
- }, _defineProperty(_class, "config", {
91
- name: "".concat(BaseClass.config.name, "WithMountWhenInView"),
92
- emits: ['scrolledInView']
93
- }), _temp;
94
- }
83
+ }, __publicField(_a, "config", {
84
+ name: `${BaseClass.config.name}WithMountWhenInView`,
85
+ emits: ["scrolledInView"]
86
+ }), _a;
87
+ }
88
+ export {
89
+ withScrolledInView as default
90
+ };
@@ -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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
23
+
24
+ // packages/js-toolkit/decorators/withVue2.js
25
+ var withVue2_exports = {};
26
+ __export(withVue2_exports, {
27
+ default: () => withVue2_default
28
+ });
29
+ module.exports = __toCommonJS(withVue2_exports);
30
+ var withVue2_default = (BaseClass, Vue) => {
31
+ var _a, _b, _c;
32
+ return _c = class extends BaseClass {
33
+ constructor(element) {
34
+ super(element);
35
+ __publicField(this, "$vue");
36
+ var _a2;
37
+ const vueConfig = (_a2 = this.vueConfig) != null ? _a2 : this.constructor.vueConfig;
38
+ if (!vueConfig) {
39
+ throw new Error("[withVue] You must define a `vueConfig` object.");
40
+ }
41
+ if (typeof vueConfig.render !== "function") {
42
+ throw new Error("[withVue] You must define a `render` function in vueConfig.");
43
+ }
44
+ this.$vue = new Vue(vueConfig);
45
+ this.$on("mounted", () => {
46
+ if (!(this.$refs.vue instanceof HTMLElement)) {
47
+ throw new Error("[withVue] The `vue` refs must be a single HTMLElement.");
48
+ }
49
+ this.$vue.$mount(this.$refs.vue);
50
+ });
51
+ this.$on("destroyed", () => {
52
+ this.$vue.$destroy();
53
+ });
54
+ }
55
+ }, __publicField(_c, "config", {
56
+ ...BaseClass.config,
57
+ name: `${BaseClass.config.name}WithVue`,
58
+ refs: [...(_b = (_a = BaseClass.config) == null ? void 0 : _a.refs) != null ? _b : [], "vue"]
59
+ }), __publicField(_c, "vueConfig"), _c;
60
+ };
61
+ if (module.exports.default) module.exports = module.exports.default;
@@ -1,45 +1,40 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- export default ((BaseClass, Vue) => {
8
- var _class, _temp, _BaseClass$config$nam, _BaseClass$config, _BaseClass$config$ref, _BaseClass$config2;
9
-
10
- return _temp = _class = class WithVue2 extends BaseClass {
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ var withVue2_default = (BaseClass, Vue) => {
8
+ var _a, _b, _c;
9
+ return _c = class extends BaseClass {
11
10
  constructor(element) {
12
11
  super(element);
13
-
14
- _defineProperty(this, "$vue", void 0);
15
-
16
- var {
17
- vueConfig
18
- } = this.constructor;
19
-
12
+ __publicField(this, "$vue");
13
+ var _a2;
14
+ const vueConfig = (_a2 = this.vueConfig) != null ? _a2 : this.constructor.vueConfig;
20
15
  if (!vueConfig) {
21
- throw new Error('[withVue] You must define a `vueConfig` object.');
16
+ throw new Error("[withVue] You must define a `vueConfig` object.");
22
17
  }
23
-
24
- if (typeof vueConfig.render !== 'function') {
25
- throw new Error('[withVue] You must define a `render` function in vueConfig.');
18
+ if (typeof vueConfig.render !== "function") {
19
+ throw new Error("[withVue] You must define a `render` function in vueConfig.");
26
20
  }
27
-
28
21
  this.$vue = new Vue(vueConfig);
29
- this.$on('mounted', () => {
22
+ this.$on("mounted", () => {
30
23
  if (!(this.$refs.vue instanceof HTMLElement)) {
31
- throw new Error('[withVue] The `vue` refs must be a single HTMLElement.');
24
+ throw new Error("[withVue] The `vue` refs must be a single HTMLElement.");
32
25
  }
33
-
34
26
  this.$vue.$mount(this.$refs.vue);
35
27
  });
36
- this.$on('destroyed', () => {
28
+ this.$on("destroyed", () => {
37
29
  this.$vue.$destroy();
38
30
  });
39
31
  }
40
-
41
- }, _defineProperty(_class, "config", _objectSpread(_objectSpread({}, BaseClass.config || {}), {}, {
42
- 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 : '', "WithVue"),
43
- refs: [...((_BaseClass$config$ref = BaseClass === null || BaseClass === void 0 ? void 0 : (_BaseClass$config2 = BaseClass.config) === null || _BaseClass$config2 === void 0 ? void 0 : _BaseClass$config2.refs) !== null && _BaseClass$config$ref !== void 0 ? _BaseClass$config$ref : []), 'vue']
44
- })), _defineProperty(_class, "vueConfig", void 0), _temp;
45
- });
32
+ }, __publicField(_c, "config", {
33
+ ...BaseClass.config,
34
+ name: `${BaseClass.config.name}WithVue`,
35
+ refs: [...(_b = (_a = BaseClass.config) == null ? void 0 : _a.refs) != null ? _b : [], "vue"]
36
+ }), __publicField(_c, "vueConfig"), _c;
37
+ };
38
+ export {
39
+ withVue2_default as default
40
+ };
@@ -0,0 +1,52 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/js-toolkit/helpers/createApp.js
20
+ var createApp_exports = {};
21
+ __export(createApp_exports, {
22
+ default: () => createApp
23
+ });
24
+ module.exports = __toCommonJS(createApp_exports);
25
+ function createApp(App, rootElement = document.body) {
26
+ let isLoaded = document.readyState === "complete";
27
+ let app;
28
+ if (!isLoaded) {
29
+ document.addEventListener("readystatechange", () => {
30
+ if (document.readyState === "complete") {
31
+ app = new App(rootElement).$mount();
32
+ isLoaded = true;
33
+ }
34
+ });
35
+ } else {
36
+ app = new App(rootElement).$mount();
37
+ }
38
+ const promise = new Promise((resolve) => {
39
+ document.addEventListener("readystatechange", () => {
40
+ if (document.readyState === "complete") {
41
+ setTimeout(() => resolve(app), 0);
42
+ }
43
+ });
44
+ });
45
+ return function useApp() {
46
+ if (isLoaded) {
47
+ return Promise.resolve(app);
48
+ }
49
+ return promise;
50
+ };
51
+ }
52
+ if (module.exports.default) module.exports = module.exports.default;
@@ -5,33 +5,10 @@
5
5
  * Instantiate and mount the given component on the given root element when the page has been loaded
6
6
  * and return a function to use the app instance when it is ready.
7
7
  *
8
- * @usage
9
- * ```js
10
- * // app.js
11
- * import Base, { createApp } from '@studiometa/js-toolkit';
12
- *
13
- * class App extends Base {
14
- * static config = {
15
- * name: 'App',
16
- * }
17
- * }
18
- *
19
- * export default createApp(App, document.body);
20
- * ```
21
- * ```js
22
- * // other.js
23
- * import useApp from './app.js';
24
- *
25
- * const app = await useApp();
26
- * console.log(app.$options.name); // 'App'
27
- * ```
28
- *
29
8
  * @template {BaseConstructor} T
30
9
  * @param {T} App
31
- * @param {HTMLElement} rootElement
32
- *
33
- * @return {() => Promise<InstanceType<T>>}
34
- *
10
+ * @param {HTMLElement} [rootElement]
11
+ * @returns {() => Promise<InstanceType<T>>}
35
12
  */
36
- export default function createApp<T extends typeof import("../Base/index.js").default>(App: T, rootElement: HTMLElement): () => Promise<InstanceType<T>>;
13
+ export default function createApp<T extends typeof import("../Base/index.js").default>(App: T, rootElement?: HTMLElement): () => Promise<InstanceType<T>>;
37
14
  export type BaseConstructor = import('../Base/index.js').BaseConstructor;