@studiometa/js-toolkit 2.0.0-rc.2 → 2.1.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 (151) hide show
  1. package/Base/index.cjs +54 -18
  2. package/Base/index.d.ts +47 -26
  3. package/Base/index.js +54 -18
  4. package/Base/managers/AbstractManager.cjs +56 -0
  5. package/Base/managers/AbstractManager.d.ts +44 -0
  6. package/Base/managers/AbstractManager.js +35 -0
  7. package/Base/managers/ChildrenManager.cjs +79 -100
  8. package/Base/managers/ChildrenManager.d.ts +8 -83
  9. package/Base/managers/ChildrenManager.js +76 -100
  10. package/Base/managers/EventsManager.cjs +75 -99
  11. package/Base/managers/EventsManager.d.ts +37 -113
  12. package/Base/managers/EventsManager.js +75 -99
  13. package/Base/managers/OptionsManager.cjs +65 -79
  14. package/Base/managers/OptionsManager.d.ts +41 -80
  15. package/Base/managers/OptionsManager.js +66 -80
  16. package/Base/managers/RefsManager.cjs +44 -68
  17. package/Base/managers/RefsManager.d.ts +12 -66
  18. package/Base/managers/RefsManager.js +41 -69
  19. package/Base/managers/ResponsiveOptionsManager.cjs +62 -0
  20. package/Base/managers/ResponsiveOptionsManager.d.ts +26 -0
  21. package/Base/managers/ResponsiveOptionsManager.js +37 -0
  22. package/Base/managers/ServicesManager.cjs +7 -10
  23. package/Base/managers/ServicesManager.d.ts +16 -19
  24. package/Base/managers/ServicesManager.js +7 -10
  25. package/Base/utils.d.ts +4 -4
  26. package/decorators/index.cjs +2 -0
  27. package/decorators/index.d.ts +1 -0
  28. package/decorators/index.js +6 -4
  29. package/decorators/withBreakpointManager.cjs +0 -1
  30. package/decorators/withBreakpointManager.d.ts +2 -2
  31. package/decorators/withBreakpointManager.js +0 -1
  32. package/decorators/withBreakpointObserver.cjs +1 -2
  33. package/decorators/withBreakpointObserver.d.ts +1 -1
  34. package/decorators/withBreakpointObserver.js +1 -2
  35. package/decorators/withDrag.d.ts +1 -1
  36. package/decorators/withExtraConfig.d.ts +1 -1
  37. package/decorators/withFreezedOptions.cjs +12 -3
  38. package/decorators/withFreezedOptions.d.ts +1 -1
  39. package/decorators/withFreezedOptions.js +13 -3
  40. package/decorators/withIntersectionObserver.cjs +0 -1
  41. package/decorators/withIntersectionObserver.d.ts +1 -1
  42. package/decorators/withIntersectionObserver.js +0 -1
  43. package/decorators/withMountWhenInView.cjs +0 -1
  44. package/decorators/withMountWhenInView.d.ts +1 -1
  45. package/decorators/withMountWhenInView.js +0 -1
  46. package/decorators/withResponsiveOptions.cjs +39 -0
  47. package/decorators/withResponsiveOptions.d.ts +8 -0
  48. package/decorators/withResponsiveOptions.js +14 -0
  49. package/decorators/withScrolledInView.cjs +58 -23
  50. package/decorators/withScrolledInView.d.ts +5 -3
  51. package/decorators/withScrolledInView.js +59 -24
  52. package/helpers/createApp.d.ts +3 -26
  53. package/helpers/getInstanceFromElement.cjs +32 -0
  54. package/helpers/getInstanceFromElement.d.ts +14 -0
  55. package/helpers/getInstanceFromElement.js +10 -0
  56. package/helpers/importOnInteraction.d.ts +3 -5
  57. package/helpers/importWhenIdle.d.ts +3 -5
  58. package/helpers/importWhenVisible.d.ts +4 -6
  59. package/helpers/index.cjs +2 -0
  60. package/helpers/index.d.ts +1 -0
  61. package/helpers/index.js +8 -6
  62. package/helpers/utils.d.ts +3 -4
  63. package/package.json +2 -1
  64. package/services/Service.d.ts +9 -9
  65. package/services/drag.cjs +0 -1
  66. package/services/drag.d.ts +3 -3
  67. package/services/drag.js +0 -1
  68. package/services/key.d.ts +1 -1
  69. package/services/load.d.ts +1 -1
  70. package/services/pointer.d.ts +1 -1
  71. package/services/raf.d.ts +1 -1
  72. package/services/resize.cjs +2 -2
  73. package/services/resize.d.ts +1 -1
  74. package/services/resize.js +2 -2
  75. package/services/scroll.cjs +3 -1
  76. package/services/scroll.d.ts +1 -1
  77. package/services/scroll.js +3 -1
  78. package/utils/collide/boundingRectToCircle.d.ts +5 -5
  79. package/utils/collide/collideCircleCircle.d.ts +4 -4
  80. package/utils/collide/collideCircleRect.d.ts +8 -8
  81. package/utils/collide/collidePointCircle.d.ts +6 -6
  82. package/utils/collide/collidePointRect.d.ts +7 -7
  83. package/utils/collide/collideRectRect.d.ts +5 -5
  84. package/utils/css/animate.cjs +190 -0
  85. package/utils/css/animate.d.ts +57 -0
  86. package/utils/css/animate.js +165 -0
  87. package/utils/css/classes.cjs +3 -3
  88. package/utils/css/classes.d.ts +10 -10
  89. package/utils/css/classes.js +3 -3
  90. package/utils/css/getOffsetSizes.cjs +47 -0
  91. package/utils/css/getOffsetSizes.d.ts +15 -0
  92. package/utils/css/getOffsetSizes.js +25 -0
  93. package/utils/css/index.cjs +6 -0
  94. package/utils/css/index.d.ts +3 -0
  95. package/utils/css/index.js +9 -4
  96. package/utils/css/matrix.d.ts +14 -15
  97. package/utils/css/styles.d.ts +2 -2
  98. package/utils/css/transform.cjs +91 -0
  99. package/utils/css/transform.d.ts +43 -0
  100. package/utils/css/transform.js +66 -0
  101. package/utils/css/transition.cjs +2 -0
  102. package/utils/css/transition.d.ts +2 -2
  103. package/utils/css/transition.js +2 -0
  104. package/utils/debounce.d.ts +4 -4
  105. package/utils/focusTrap.cjs +1 -1
  106. package/utils/focusTrap.d.ts +1 -0
  107. package/utils/focusTrap.js +1 -1
  108. package/utils/history.d.ts +13 -11
  109. package/utils/index.cjs +4 -0
  110. package/utils/index.d.ts +2 -0
  111. package/utils/index.js +4 -0
  112. package/utils/isDefined.cjs +28 -0
  113. package/utils/isDefined.d.ts +7 -0
  114. package/utils/isDefined.js +6 -0
  115. package/utils/isFunction.cjs +28 -0
  116. package/utils/isFunction.d.ts +7 -0
  117. package/utils/isFunction.js +6 -0
  118. package/utils/math/clamp.d.ts +1 -1
  119. package/utils/math/clamp01.d.ts +1 -1
  120. package/utils/math/damp.d.ts +6 -6
  121. package/utils/math/ease.d.ts +7 -7
  122. package/utils/math/index.cjs +2 -0
  123. package/utils/math/index.d.ts +1 -0
  124. package/utils/math/index.js +2 -0
  125. package/utils/math/inertiaFinalValue.d.ts +5 -5
  126. package/utils/math/lerp.d.ts +4 -4
  127. package/utils/math/map.d.ts +6 -6
  128. package/utils/math/round.d.ts +4 -4
  129. package/utils/memoize.d.ts +1 -1
  130. package/utils/nextFrame.d.ts +3 -4
  131. package/utils/nextMicrotask.d.ts +1 -1
  132. package/utils/nextTick.d.ts +1 -1
  133. package/utils/object/autoBind.d.ts +3 -3
  134. package/utils/object/getAllProperties.d.ts +3 -3
  135. package/utils/object/isObject.d.ts +1 -1
  136. package/utils/scrollTo.cjs +1 -1
  137. package/utils/scrollTo.d.ts +1 -1
  138. package/utils/scrollTo.js +1 -1
  139. package/utils/string/withLeadingCharacters.d.ts +3 -2
  140. package/utils/string/withLeadingSlash.d.ts +1 -1
  141. package/utils/string/withTrailingCharacters.d.ts +3 -2
  142. package/utils/string/withTrailingSlash.d.ts +1 -1
  143. package/utils/string/withoutLeadingCharacters.d.ts +3 -2
  144. package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
  145. package/utils/string/withoutLeadingSlash.d.ts +1 -1
  146. package/utils/string/withoutTrailingCharacters.d.ts +3 -2
  147. package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
  148. package/utils/string/withoutTrailingSlash.d.ts +1 -1
  149. package/utils/throttle.cjs +1 -1
  150. package/utils/throttle.d.ts +3 -3
  151. package/utils/throttle.js +1 -1
@@ -29,6 +29,7 @@ __export(decorators_exports, {
29
29
  withFreezedOptions: () => import_withFreezedOptions.default,
30
30
  withIntersectionObserver: () => import_withIntersectionObserver.default,
31
31
  withMountWhenInView: () => import_withMountWhenInView.default,
32
+ withResponsiveOptions: () => import_withResponsiveOptions.default,
32
33
  withScrolledInView: () => import_withScrolledInView.default,
33
34
  withVue2: () => import_withVue2.default
34
35
  });
@@ -40,6 +41,7 @@ var import_withExtraConfig = __toESM(require("./withExtraConfig.cjs"), 1);
40
41
  var import_withFreezedOptions = __toESM(require("./withFreezedOptions.cjs"), 1);
41
42
  var import_withIntersectionObserver = __toESM(require("./withIntersectionObserver.cjs"), 1);
42
43
  var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
44
+ var import_withResponsiveOptions = __toESM(require("./withResponsiveOptions.cjs"), 1);
43
45
  var import_withScrolledInView = __toESM(require("./withScrolledInView.cjs"), 1);
44
46
  var import_withVue2 = __toESM(require("./withVue2.cjs"), 1);
45
47
  if (module.exports.default) module.exports = module.exports.default;
@@ -5,5 +5,6 @@ export { default as withExtraConfig } from "./withExtraConfig.js";
5
5
  export { default as withFreezedOptions } from "./withFreezedOptions.js";
6
6
  export { default as withIntersectionObserver } from "./withIntersectionObserver.js";
7
7
  export { default as withMountWhenInView } from "./withMountWhenInView.js";
8
+ export { default as withResponsiveOptions } from "./withResponsiveOptions.js";
8
9
  export { default as withScrolledInView } from "./withScrolledInView.js";
9
10
  export { default as withVue2 } from "./withVue2.js";
@@ -5,8 +5,9 @@ import { default as default5 } from "./withExtraConfig.js";
5
5
  import { default as default6 } from "./withFreezedOptions.js";
6
6
  import { default as default7 } from "./withIntersectionObserver.js";
7
7
  import { default as default8 } from "./withMountWhenInView.js";
8
- import { default as default9 } from "./withScrolledInView.js";
9
- import { default as default10 } from "./withVue2.js";
8
+ import { default as default9 } from "./withResponsiveOptions.js";
9
+ import { default as default10 } from "./withScrolledInView.js";
10
+ import { default as default11 } from "./withVue2.js";
10
11
  export {
11
12
  default2 as withBreakpointManager,
12
13
  default3 as withBreakpointObserver,
@@ -15,6 +16,7 @@ export {
15
16
  default6 as withFreezedOptions,
16
17
  default7 as withIntersectionObserver,
17
18
  default8 as withMountWhenInView,
18
- default9 as withScrolledInView,
19
- default10 as withVue2
19
+ default9 as withResponsiveOptions,
20
+ default10 as withScrolledInView,
21
+ default11 as withVue2
20
22
  };
@@ -65,7 +65,6 @@ function withBreakpointManager(BaseClass, breakpoints) {
65
65
  testBreakpoints(instances.get(this));
66
66
  });
67
67
  this.instances = instances.get(this);
68
- return this;
69
68
  }
70
69
  $mount() {
71
70
  super.$mount();
@@ -2,8 +2,8 @@
2
2
  * BreakpointManager class.
3
3
  * @template {BaseConstructor} T
4
4
  * @param {T} BaseClass
5
- * @param {Array<[String, BaseConstructor]>} breakpoints
6
- * @return {T}
5
+ * @param {Array<[string, BaseConstructor]>} breakpoints
6
+ * @returns {T}
7
7
  */
8
8
  export default function withBreakpointManager<T extends typeof import("../Base").default>(BaseClass: T, breakpoints: Array<[string, BaseConstructor]>): T;
9
9
  export type Base = import('../Base').default;
@@ -38,7 +38,6 @@ function withBreakpointManager(BaseClass, breakpoints) {
38
38
  testBreakpoints(instances.get(this));
39
39
  });
40
40
  this.instances = instances.get(this);
41
- return this;
42
41
  }
43
42
  $mount() {
44
43
  super.$mount();
@@ -87,10 +87,9 @@ function withBreakpointObserver(BaseClass) {
87
87
  });
88
88
  mutationObserver.observe(this.$el, { attributes: true });
89
89
  if (!hasBreakpointConfiguration(this)) {
90
- return this;
90
+ return;
91
91
  }
92
92
  addToResize(key, this);
93
- return this;
94
93
  }
95
94
  $mount() {
96
95
  if (!hasBreakpointConfiguration(this)) {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @template {BaseConstructor} T
5
5
  * @param {T} BaseClass The Base class to extend from.
6
- * @return {T}
6
+ * @returns {T}
7
7
  */
8
8
  export default function withBreakpointObserver<T extends typeof import("../Base").default>(BaseClass: T): T;
9
9
  export type Base = import('../Base').default;
@@ -61,10 +61,9 @@ function withBreakpointObserver(BaseClass) {
61
61
  });
62
62
  mutationObserver.observe(this.$el, { attributes: true });
63
63
  if (!hasBreakpointConfiguration(this)) {
64
- return this;
64
+ return;
65
65
  }
66
66
  addToResize(key, this);
67
- return this;
68
67
  }
69
68
  $mount() {
70
69
  if (!hasBreakpointConfiguration(this)) {
@@ -12,7 +12,7 @@
12
12
  * @template {BaseConstructor} T
13
13
  * @param {T} BaseClass
14
14
  * @param {DragDecoratorOptions} options
15
- * @return {T}
15
+ * @returns {T}
16
16
  */
17
17
  export default function withDrag<T extends typeof import("../Base").default>(BaseClass: T, { target, ...options }?: DragDecoratorOptions): T;
18
18
  export type Base = import('../Base').default;
@@ -10,7 +10,7 @@
10
10
  * @param {T} BaseClass The Base class to extend.
11
11
  * @param {Partial<BaseConfig>} config Extra configuration to merge.
12
12
  * @param {DeepmergeOptions} options Options for the `deepmerge` function. {@link https://github.com/TehShrike/deepmerge#options}
13
- * @return {T}
13
+ * @returns {T}
14
14
  */
15
15
  export default function withExtraConfig<T extends typeof import("../Base").default>(BaseClass: T, config: Partial<BaseConfig>, options?: DeepmergeOptions): T;
16
16
  export type DeepmergeOptions = import('deepmerge').Options;
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
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;
5
6
  var __export = (target, all) => {
6
7
  for (var name in all)
7
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,6 +16,10 @@ var __copyProps = (to, from, except, desc) => {
15
16
  return to;
16
17
  };
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
+ };
18
23
 
19
24
  // packages/js-toolkit/decorators/withFreezedOptions.js
20
25
  var withFreezedOptions_exports = {};
@@ -24,13 +29,17 @@ __export(withFreezedOptions_exports, {
24
29
  module.exports = __toCommonJS(withFreezedOptions_exports);
25
30
  function withFreezedOptions(BaseClass) {
26
31
  return class extends BaseClass {
32
+ constructor() {
33
+ super(...arguments);
34
+ __publicField(this, "__freezedOptions");
35
+ }
27
36
  get $options() {
28
- Object.defineProperty(this, "$options", {
37
+ Object.defineProperty(this, "__freezedOptions", {
29
38
  value: Object.freeze({ ...super.$options }),
30
- enumerable: true,
39
+ enumerable: false,
31
40
  configurable: true
32
41
  });
33
- return this.$options;
42
+ return this.__freezedOptions;
34
43
  }
35
44
  };
36
45
  }
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @template {BaseConstructor} T
9
9
  * @param {T} BaseClass The Base class to extend.
10
- * @return {T}
10
+ * @returns {T}
11
11
  */
12
12
  export default function withFreezedOptions<T extends typeof import("../Base").default>(BaseClass: T): T;
13
13
  export type BaseOptions = import('../Base').BaseOptions;
@@ -1,12 +1,22 @@
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
+ };
1
7
  function withFreezedOptions(BaseClass) {
2
8
  return class extends BaseClass {
9
+ constructor() {
10
+ super(...arguments);
11
+ __publicField(this, "__freezedOptions");
12
+ }
3
13
  get $options() {
4
- Object.defineProperty(this, "$options", {
14
+ Object.defineProperty(this, "__freezedOptions", {
5
15
  value: Object.freeze({ ...super.$options }),
6
- enumerable: true,
16
+ enumerable: false,
7
17
  configurable: true
8
18
  });
9
- return this.$options;
19
+ return this.__freezedOptions;
10
20
  }
11
21
  };
12
22
  }
@@ -47,7 +47,6 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
47
47
  this.$on("destroyed", () => {
48
48
  this.$observer.unobserve(this.$el);
49
49
  });
50
- return this;
51
50
  }
52
51
  }, __publicField(_b, "config", {
53
52
  ...BaseClass.config,
@@ -4,7 +4,7 @@
4
4
  * @template {BaseConstructor} T
5
5
  * @param {T} BaseClass The Base class to extend.
6
6
  * @param {Object} [defaultOptions] The options for the IntersectionObserver instance.
7
- * @return {T & { new: (element:HTMLElement) => { $observer: IntersectionObserver }}}
7
+ * @returns {T & { new: (element:HTMLElement) => { $observer: IntersectionObserver }}}
8
8
  */
9
9
  export default function withIntersectionObserver<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: any): T & {
10
10
  new: (element: HTMLElement) => {
@@ -24,7 +24,6 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
24
24
  this.$on("destroyed", () => {
25
25
  this.$observer.unobserve(this.$el);
26
26
  });
27
- return this;
28
27
  }
29
28
  }, __publicField(_b, "config", {
30
29
  ...BaseClass.config,
@@ -49,7 +49,6 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
49
49
  this.$on("terminated", () => {
50
50
  this.__observer.disconnect();
51
51
  });
52
- return this;
53
52
  }
54
53
  $mount() {
55
54
  if (this.__isVisible) {
@@ -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;
@@ -26,7 +26,6 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
26
26
  this.$on("terminated", () => {
27
27
  this.__observer.disconnect();
28
28
  });
29
- return this;
30
29
  }
31
30
  $mount() {
32
31
  if (this.__isVisible) {
@@ -0,0 +1,39 @@
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 __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ 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));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // packages/js-toolkit/decorators/withResponsiveOptions.js
23
+ var withResponsiveOptions_exports = {};
24
+ __export(withResponsiveOptions_exports, {
25
+ default: () => withResponsiveOptions
26
+ });
27
+ module.exports = __toCommonJS(withResponsiveOptions_exports);
28
+ var import_ResponsiveOptionsManager = __toESM(require("../Base/managers/ResponsiveOptionsManager.cjs"), 1);
29
+ function withResponsiveOptions(BaseClass) {
30
+ return class extends BaseClass {
31
+ get __managers() {
32
+ return {
33
+ ...super.__managers,
34
+ OptionsManager: import_ResponsiveOptionsManager.default
35
+ };
36
+ }
37
+ };
38
+ }
39
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Extends the configuration of an existing class.
3
+ *
4
+ * @template {import('../Base').BaseConstructor} T
5
+ * @param {T} BaseClass The Base class to extend.
6
+ * @returns {T}
7
+ */
8
+ export default function withResponsiveOptions<T extends typeof import("../Base").default>(BaseClass: T): T;
@@ -0,0 +1,14 @@
1
+ import ResponsiveOptionsManager from "../Base/managers/ResponsiveOptionsManager.js";
2
+ function withResponsiveOptions(BaseClass) {
3
+ return class extends BaseClass {
4
+ get __managers() {
5
+ return {
6
+ ...super.__managers,
7
+ OptionsManager: ResponsiveOptionsManager
8
+ };
9
+ }
10
+ };
11
+ }
12
+ export {
13
+ withResponsiveOptions as default
14
+ };
@@ -32,11 +32,11 @@ __export(withScrolledInView_exports, {
32
32
  module.exports = __toCommonJS(withScrolledInView_exports);
33
33
  var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
34
34
  var import_utils = require("../utils/index.cjs");
35
- function withScrolledInView(BaseClass, options) {
35
+ function withScrolledInView(BaseClass, options = {}) {
36
36
  var _a;
37
37
  return _a = class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
38
- constructor() {
39
- super(...arguments);
38
+ constructor(element) {
39
+ super(element);
40
40
  __publicField(this, "__props", {
41
41
  start: {
42
42
  x: 0,
@@ -61,37 +61,72 @@ function withScrolledInView(BaseClass, options) {
61
61
  });
62
62
  __publicField(this, "dampFactor", 0.1);
63
63
  __publicField(this, "dampPrecision", 1e-3);
64
+ const delegate = {
65
+ handleEvent(event) {
66
+ delegate[event.type](event.detail[0]);
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
+ };
89
+ this.$on("before-mounted", () => {
90
+ this.$on("resized", delegate);
91
+ this.$on("scrolled", delegate);
92
+ this.$on("ticked", delegate);
93
+ });
94
+ this.$on("mounted", () => {
95
+ this.__setProps();
96
+ });
97
+ this.$on("destroyed", () => {
98
+ this.$off("resized", delegate);
99
+ this.$off("scrolled", delegate);
100
+ this.$off("ticked", delegate);
101
+ });
64
102
  }
65
103
  mounted() {
66
- this.__setProps();
104
+ if ((0, import_utils.isFunction)(super.mounted))
105
+ super.mounted();
67
106
  }
68
- resized() {
69
- this.__setProps();
107
+ resized(props) {
108
+ if ((0, import_utils.isFunction)(super.resized))
109
+ super.resized(props);
70
110
  }
71
111
  scrolled(props) {
72
- if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
73
- this.$services.enable("ticked");
74
- }
112
+ if ((0, import_utils.isFunction)(super.scrolled))
113
+ super.scrolled(props);
114
+ }
115
+ ticked(props) {
116
+ if ((0, import_utils.isFunction)(super.ticked))
117
+ super.ticked(props);
75
118
  }
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);
119
+ destroyed() {
120
+ if ((0, import_utils.isFunction)(super.destroyed))
121
+ super.destroyed();
87
122
  }
88
123
  __setProps() {
89
- const sizes = this.$el.getBoundingClientRect();
90
- const yEnd = sizes.top + window.pageYOffset + sizes.height;
124
+ const sizes = options.useOffsetSizes ? (0, import_utils.getOffsetSizes)(this.$el) : this.$el.getBoundingClientRect();
125
+ const yEnd = sizes.y + window.pageYOffset + sizes.height;
91
126
  const yStart = yEnd - window.innerHeight - sizes.height;
92
127
  const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
93
128
  const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
94
- const xEnd = sizes.left + window.pageXOffset + sizes.width;
129
+ const xEnd = sizes.x + window.pageXOffset + sizes.width;
95
130
  const xStart = xEnd - window.innerWidth - sizes.width;
96
131
  const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
97
132
  const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
@@ -8,10 +8,12 @@
8
8
  *
9
9
  * @template {BaseConstructor} T
10
10
  * @param {T} BaseClass
11
- * @param {IntersectionObserverInit} options
12
- * @return {T}
11
+ * @param {IntersectionObserverInit & { useOffsetSizes?: boolean }} options
12
+ * @returns {T}
13
13
  */
14
- export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options: IntersectionObserverInit): T;
14
+ export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options?: IntersectionObserverInit & {
15
+ useOffsetSizes?: boolean;
16
+ }): T;
15
17
  export type Base = import('../Base').default;
16
18
  export type BaseConstructor = import('../Base').BaseConstructor;
17
19
  export type BaseConfig = import('../Base').BaseConfig;
@@ -5,12 +5,12 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import withMountWhenInView from "./withMountWhenInView.js";
8
- import { damp, clamp, clamp01 } from "../utils/index.js";
9
- function withScrolledInView(BaseClass, options) {
8
+ import { damp, clamp, clamp01, getOffsetSizes, isFunction } from "../utils/index.js";
9
+ function withScrolledInView(BaseClass, options = {}) {
10
10
  var _a;
11
11
  return _a = class extends withMountWhenInView(BaseClass, options) {
12
- constructor() {
13
- super(...arguments);
12
+ constructor(element) {
13
+ super(element);
14
14
  __publicField(this, "__props", {
15
15
  start: {
16
16
  x: 0,
@@ -35,37 +35,72 @@ function withScrolledInView(BaseClass, options) {
35
35
  });
36
36
  __publicField(this, "dampFactor", 0.1);
37
37
  __publicField(this, "dampPrecision", 1e-3);
38
+ const delegate = {
39
+ handleEvent(event) {
40
+ delegate[event.type](event.detail[0]);
41
+ },
42
+ resized: () => {
43
+ this.__setProps();
44
+ },
45
+ scrolled: (props) => {
46
+ if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
47
+ this.$services.enable("ticked");
48
+ }
49
+ },
50
+ ticked: () => {
51
+ this.__props.current.x = clamp(window.pageXOffset, this.__props.start.x, this.__props.end.x);
52
+ this.__props.progress.x = clamp01((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
53
+ this.__props.dampedProgress.x = damp(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
54
+ this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
55
+ this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
56
+ this.__props.dampedProgress.y = damp(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
57
+ if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
58
+ this.$services.disable("ticked");
59
+ }
60
+ this.__callMethod("scrolledInView", this.__props);
61
+ }
62
+ };
63
+ this.$on("before-mounted", () => {
64
+ this.$on("resized", delegate);
65
+ this.$on("scrolled", delegate);
66
+ this.$on("ticked", delegate);
67
+ });
68
+ this.$on("mounted", () => {
69
+ this.__setProps();
70
+ });
71
+ this.$on("destroyed", () => {
72
+ this.$off("resized", delegate);
73
+ this.$off("scrolled", delegate);
74
+ this.$off("ticked", delegate);
75
+ });
38
76
  }
39
77
  mounted() {
40
- this.__setProps();
78
+ if (isFunction(super.mounted))
79
+ super.mounted();
41
80
  }
42
- resized() {
43
- this.__setProps();
81
+ resized(props) {
82
+ if (isFunction(super.resized))
83
+ super.resized(props);
44
84
  }
45
85
  scrolled(props) {
46
- if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
47
- this.$services.enable("ticked");
48
- }
86
+ if (isFunction(super.scrolled))
87
+ super.scrolled(props);
88
+ }
89
+ ticked(props) {
90
+ if (isFunction(super.ticked))
91
+ super.ticked(props);
49
92
  }
50
- ticked() {
51
- this.__props.current.x = clamp(window.pageXOffset, this.__props.start.x, this.__props.end.x);
52
- this.__props.progress.x = clamp01((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
53
- this.__props.dampedProgress.x = damp(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
54
- this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
55
- this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
56
- this.__props.dampedProgress.y = damp(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
57
- if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
58
- this.$services.disable("ticked");
59
- }
60
- this.__callMethod("scrolledInView", this.__props);
93
+ destroyed() {
94
+ if (isFunction(super.destroyed))
95
+ super.destroyed();
61
96
  }
62
97
  __setProps() {
63
- const sizes = this.$el.getBoundingClientRect();
64
- const yEnd = sizes.top + window.pageYOffset + sizes.height;
98
+ const sizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
99
+ const yEnd = sizes.y + window.pageYOffset + sizes.height;
65
100
  const yStart = yEnd - window.innerHeight - sizes.height;
66
101
  const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
67
102
  const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
68
- const xEnd = sizes.left + window.pageXOffset + sizes.width;
103
+ const xEnd = sizes.x + window.pageXOffset + sizes.width;
69
104
  const xStart = xEnd - window.innerWidth - sizes.width;
70
105
  const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
71
106
  const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
@@ -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 | undefined): () => 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;
@@ -0,0 +1,32 @@
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/getInstanceFromElement.js
20
+ var getInstanceFromElement_exports = {};
21
+ __export(getInstanceFromElement_exports, {
22
+ default: () => getInstanceFromElement
23
+ });
24
+ module.exports = __toCommonJS(getInstanceFromElement_exports);
25
+ function getInstanceFromElement(element, Constructor) {
26
+ var _a;
27
+ if (!element.__base__) {
28
+ return null;
29
+ }
30
+ return (_a = element.__base__.get(Constructor)) != null ? _a : null;
31
+ }
32
+ if (module.exports.default) module.exports = module.exports.default;