@studiometa/js-toolkit 2.4.4-alpha.3 → 2.4.4-alpha.6

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 (71) hide show
  1. package/Base/index.cjs +1 -1
  2. package/Base/index.d.ts +16 -18
  3. package/Base/index.js +1 -1
  4. package/Base/managers/AbstractManager.d.ts +2 -2
  5. package/Base/managers/ChildrenManager.cjs +2 -4
  6. package/Base/managers/ChildrenManager.d.ts +2 -10
  7. package/Base/managers/ChildrenManager.js +1 -3
  8. package/Base/managers/EventsManager.cjs +3 -3
  9. package/Base/managers/EventsManager.d.ts +9 -15
  10. package/Base/managers/EventsManager.js +2 -2
  11. package/Base/managers/OptionsManager.d.ts +2 -2
  12. package/Base/managers/ServicesManager.d.ts +1 -1
  13. package/Base/types.d.ts +5 -1
  14. package/Base/utils.cjs +1 -1
  15. package/Base/utils.d.ts +5 -21
  16. package/decorators/index.cjs +11 -32
  17. package/decorators/index.d.ts +10 -10
  18. package/decorators/index.js +10 -22
  19. package/decorators/withBreakpointManager.cjs +9 -14
  20. package/decorators/withBreakpointManager.d.ts +3 -56
  21. package/decorators/withBreakpointManager.js +7 -6
  22. package/decorators/withBreakpointObserver.cjs +11 -15
  23. package/decorators/withBreakpointObserver.d.ts +12 -62
  24. package/decorators/withBreakpointObserver.js +8 -6
  25. package/decorators/withDrag.cjs +10 -15
  26. package/decorators/withDrag.d.ts +8 -51
  27. package/decorators/withDrag.js +9 -8
  28. package/decorators/withExtraConfig.cjs +5 -4
  29. package/decorators/withExtraConfig.d.ts +3 -53
  30. package/decorators/withExtraConfig.js +5 -4
  31. package/decorators/withFreezedOptions.cjs +4 -3
  32. package/decorators/withFreezedOptions.d.ts +6 -53
  33. package/decorators/withFreezedOptions.js +4 -3
  34. package/decorators/withIntersectionObserver.cjs +7 -5
  35. package/decorators/withIntersectionObserver.d.ts +4 -63
  36. package/decorators/withIntersectionObserver.js +7 -5
  37. package/decorators/withMountWhenInView.cjs +11 -6
  38. package/decorators/withMountWhenInView.d.ts +16 -61
  39. package/decorators/withMountWhenInView.js +11 -6
  40. package/decorators/withResponsiveOptions.cjs +4 -3
  41. package/decorators/withResponsiveOptions.d.ts +3 -50
  42. package/decorators/withResponsiveOptions.js +4 -3
  43. package/decorators/withScrolledInView.cjs +25 -18
  44. package/decorators/withScrolledInView.d.ts +30 -141
  45. package/decorators/withScrolledInView.js +25 -12
  46. package/decorators/withVue2.cjs +8 -5
  47. package/decorators/withVue2.d.ts +8 -62
  48. package/decorators/withVue2.js +8 -5
  49. package/helpers/createApp.cjs +1 -1
  50. package/helpers/createApp.d.ts +2 -10
  51. package/helpers/getDirectChildren.cjs +5 -5
  52. package/helpers/getDirectChildren.d.ts +3 -6
  53. package/helpers/getDirectChildren.js +4 -4
  54. package/helpers/getInstanceFromElement.cjs +3 -4
  55. package/helpers/getInstanceFromElement.d.ts +2 -11
  56. package/helpers/getInstanceFromElement.js +2 -3
  57. package/helpers/importOnInteraction.cjs +1 -1
  58. package/helpers/importOnInteraction.d.ts +4 -9
  59. package/helpers/importWhenIdle.cjs +3 -5
  60. package/helpers/importWhenIdle.d.ts +7 -10
  61. package/helpers/importWhenIdle.js +2 -4
  62. package/helpers/importWhenVisible.cjs +1 -1
  63. package/helpers/importWhenVisible.d.ts +2 -7
  64. package/helpers/index.cjs +1 -1
  65. package/helpers/index.d.ts +6 -6
  66. package/helpers/utils.cjs +1 -1
  67. package/helpers/utils.d.ts +1 -1
  68. package/index.cjs +2 -8
  69. package/index.d.ts +2 -2
  70. package/index.js +2 -2
  71. package/package.json +1 -1
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import withMountWhenInView from "./withMountWhenInView.js";
7
+ import { withMountWhenInView } from "./withMountWhenInView.js";
8
8
  import { damp, clamp, clamp01, getOffsetSizes, isFunction, useScheduler } from "../utils/index.js";
9
9
  const scheduler = useScheduler(["update", "render"]);
10
10
  function updateProps(props, dampFactor, dampPrecision, axis = "x") {
@@ -27,9 +27,7 @@ function updateProps(props, dampFactor, dampPrecision, axis = "x") {
27
27
  );
28
28
  }
29
29
  function withScrolledInView(BaseClass, options = {}) {
30
- var _a;
31
- const WithMountWhenInView = withMountWhenInView(BaseClass, options);
32
- return _a = class extends WithMountWhenInView {
30
+ class WithScrolledInView extends withMountWhenInView(BaseClass, options) {
33
31
  constructor(element) {
34
32
  super(element);
35
33
  __publicField(this, "__props", {
@@ -58,8 +56,8 @@ function withScrolledInView(BaseClass, options = {}) {
58
56
  y: 0
59
57
  }
60
58
  });
61
- __publicField(this, "dampFactor", 0.1);
62
- __publicField(this, "dampPrecision", 1e-3);
59
+ __publicField(this, "dampFactor", null);
60
+ __publicField(this, "dampPrecision", null);
63
61
  const render = () => {
64
62
  scheduler.update(() => {
65
63
  const renderFn = this.__callMethod("scrolledInView", this.__props);
@@ -83,8 +81,11 @@ function withScrolledInView(BaseClass, options = {}) {
83
81
  }
84
82
  },
85
83
  ticked: () => {
86
- updateProps(this.__props, this.dampFactor, this.dampPrecision, "x");
87
- updateProps(this.__props, this.dampFactor, this.dampPrecision, "y");
84
+ var _a, _b;
85
+ const dampFactor = (_a = this.dampFactor) != null ? _a : this.$options.dampFactor;
86
+ const dampPrecision = (_b = this.dampFactor) != null ? _b : this.$options.dampFactor;
87
+ updateProps(this.__props, dampFactor, dampPrecision, "x");
88
+ updateProps(this.__props, dampFactor, dampPrecision, "y");
88
89
  if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
89
90
  this.$services.disable("ticked");
90
91
  }
@@ -172,11 +173,23 @@ function withScrolledInView(BaseClass, options = {}) {
172
173
  (this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
173
174
  );
174
175
  }
175
- }, __publicField(_a, "config", {
176
+ }
177
+ __publicField(WithScrolledInView, "config", {
176
178
  name: `${BaseClass.config.name}WithMountWhenInView`,
177
- emits: ["scrolledInView"]
178
- }), _a;
179
+ emits: ["scrolledInView"],
180
+ options: {
181
+ dampFactor: {
182
+ type: Number,
183
+ default: 0.1
184
+ },
185
+ dampPrecision: {
186
+ type: Number,
187
+ default: 1e-3
188
+ }
189
+ }
190
+ });
191
+ return WithScrolledInView;
179
192
  }
180
193
  export {
181
- withScrolledInView as default
194
+ withScrolledInView
182
195
  };
@@ -24,13 +24,13 @@ var __publicField = (obj, key, value) => {
24
24
  // packages/js-toolkit/decorators/withVue2.ts
25
25
  var withVue2_exports = {};
26
26
  __export(withVue2_exports, {
27
- default: () => withVue2
27
+ withVue2: () => withVue2
28
28
  });
29
29
  module.exports = __toCommonJS(withVue2_exports);
30
30
  var import_utils = require("../utils/index.cjs");
31
31
  function withVue2(BaseClass, VueCtor) {
32
- var _a, _b, _c;
33
- return _c = class extends BaseClass {
32
+ var _a, _b;
33
+ class WithVue2 extends BaseClass {
34
34
  constructor(element) {
35
35
  var _a2;
36
36
  super(element);
@@ -59,10 +59,13 @@ function withVue2(BaseClass, VueCtor) {
59
59
  this.$vue.$destroy();
60
60
  });
61
61
  }
62
- }, __publicField(_c, "config", {
62
+ }
63
+ __publicField(WithVue2, "config", {
63
64
  ...BaseClass.config,
64
65
  name: `${BaseClass.config.name}WithVue`,
65
66
  refs: [...(_b = (_a = BaseClass.config) == null ? void 0 : _a.refs) != null ? _b : [], "vue"]
66
- }), __publicField(_c, "vueConfig"), _c;
67
+ });
68
+ __publicField(WithVue2, "vueConfig");
69
+ return WithVue2;
67
70
  }
68
71
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,70 +1,16 @@
1
1
  import type Vue from 'vue';
2
- import type { ComponentOptions, VueConstructor } from 'vue';
3
- import type { BaseConstructor, BaseTypeParameter } from '../Base/index.js';
4
- interface WithVue2Interface {
2
+ import type { VueConstructor } from 'vue';
3
+ import type { BaseDecorator, BaseInterface } from '../Base/types.js';
4
+ import type { Base, BaseTypeParameter } from '../Base/index.js';
5
+ export interface WithVue2TypeParameter extends BaseTypeParameter {
5
6
  $refs: {
6
7
  vue: HTMLElement;
7
8
  };
8
9
  }
10
+ export interface WithVue2Interface extends BaseInterface {
11
+ $vue: Vue;
12
+ }
9
13
  /**
10
14
  * withVue decorator.
11
15
  */
12
- export default function withVue2<T extends BaseTypeParameter = BaseTypeParameter, VueTypeParameter extends Vue = Vue>(BaseClass: BaseConstructor, VueCtor: VueConstructor): {
13
- new <U extends BaseTypeParameter = BaseTypeParameter>(element: HTMLElement): {
14
- $vue: Vue;
15
- $parent: import("../Base/index.js").default<BaseTypeParameter>;
16
- $id: string;
17
- $el: (WithVue2Interface & T & U)["$el"] & HTMLElement & {
18
- __base__?: WeakMap<typeof import("../Base/index.js").default, import("../Base/index.js").default<BaseTypeParameter> | "terminated">;
19
- };
20
- $isMounted: boolean;
21
- __eventHandlers: Map<string, Set<EventListenerOrEventListenerObject>>;
22
- readonly $root: import("../Base/index.js").default<BaseTypeParameter>;
23
- readonly __config: import("../Base/index.js").BaseConfig;
24
- __services: import("../Base/managers/ServicesManager.js").default;
25
- readonly $services: import("../Base/managers/ServicesManager.js").default;
26
- __refs: import("../Base/managers/RefsManager.js").default & (WithVue2Interface & T & U)["$refs"] & import("../Base/index.js").BaseRefs;
27
- readonly $refs: import("../Base/managers/RefsManager.js").default & (WithVue2Interface & T & U)["$refs"] & import("../Base/index.js").BaseRefs;
28
- __options: import("../Base/managers/OptionsManager.js").default & (WithVue2Interface & T & U)["$options"] & import("../Base/index.js").BaseOptions;
29
- readonly $options: import("../Base/managers/OptionsManager.js").default & (WithVue2Interface & T & U)["$options"] & import("../Base/index.js").BaseOptions;
30
- __children: import("../Base/managers/ChildrenManager.js").default & ((WithVue2Interface & T & U)["$children"] extends infer T_1 ? { [key in keyof T_1]: (WithVue2Interface & T & U)["$children"][key][]; } : never) & import("../Base/index.js").BaseChildren;
31
- readonly $children: import("../Base/managers/ChildrenManager.js").default & ((WithVue2Interface & T & U)["$children"] extends infer T_2 ? { [key_1 in keyof T_2]: (WithVue2Interface & T & U)["$children"][key_1][]; } : never) & import("../Base/index.js").BaseChildren;
32
- __events: import("../Base/managers/EventsManager.js").default;
33
- readonly $log: (...args: any) => void;
34
- readonly __debug: (...args: any) => void;
35
- readonly __managers: import("../Base/index.js").Managers;
36
- __callMethod(method: string, ...args: unknown[]): unknown;
37
- __hasEvent(event: string): boolean;
38
- $mount(): any;
39
- $update(): any;
40
- $destroy(): any;
41
- $terminate(): void;
42
- __addEmits(event: string): void;
43
- __removeEmits(event: string): void;
44
- readonly __ctor: typeof import("../Base/index.js").default;
45
- $on(event: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): () => void;
46
- $off(event: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
47
- $emit(event: string, ...args: unknown[]): void;
48
- addEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
49
- dispatchEvent(event: Event): boolean;
50
- removeEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
51
- };
52
- config: {
53
- name: string;
54
- refs: string[];
55
- debug?: boolean;
56
- log?: boolean;
57
- emits?: string[];
58
- components?: import("../Base/index.js").BaseConfigComponents;
59
- options?: import("../Base/managers/OptionsManager.js").OptionsSchema;
60
- };
61
- /**
62
- * Vue app configuration.
63
- */
64
- vueConfig: ComponentOptions<VueTypeParameter, import("vue/types/options.js").DefaultData<VueTypeParameter>, import("vue/types/options.js").DefaultMethods<VueTypeParameter>, import("vue/types/options.js").DefaultComputed, import("vue/types/options.js").PropsDefinition<import("vue/types/options.js").DefaultProps>, import("vue/types/options.js").DefaultProps> & {
65
- render: ComponentOptions<VueTypeParameter>['render'];
66
- };
67
- readonly $isBase: true;
68
- $factory(nameOrSelector: string): import("../Base/index.js").default<BaseTypeParameter>[];
69
- };
70
- export {};
16
+ export declare function withVue2<S extends Base, VueTypeParameter extends Vue = Vue>(BaseClass: typeof Base, VueCtor: VueConstructor): BaseDecorator<WithVue2Interface, S>;
@@ -6,8 +6,8 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import { isDev, isFunction } from "../utils/index.js";
8
8
  function withVue2(BaseClass, VueCtor) {
9
- var _a, _b, _c;
10
- return _c = class extends BaseClass {
9
+ var _a, _b;
10
+ class WithVue2 extends BaseClass {
11
11
  constructor(element) {
12
12
  var _a2;
13
13
  super(element);
@@ -36,12 +36,15 @@ function withVue2(BaseClass, VueCtor) {
36
36
  this.$vue.$destroy();
37
37
  });
38
38
  }
39
- }, __publicField(_c, "config", {
39
+ }
40
+ __publicField(WithVue2, "config", {
40
41
  ...BaseClass.config,
41
42
  name: `${BaseClass.config.name}WithVue`,
42
43
  refs: [...(_b = (_a = BaseClass.config) == null ? void 0 : _a.refs) != null ? _b : [], "vue"]
43
- }), __publicField(_c, "vueConfig"), _c;
44
+ });
45
+ __publicField(WithVue2, "vueConfig");
46
+ return WithVue2;
44
47
  }
45
48
  export {
46
- withVue2 as default
49
+ withVue2
47
50
  };
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/createApp.js
19
+ // packages/js-toolkit/helpers/createApp.ts
20
20
  var createApp_exports = {};
21
21
  __export(createApp_exports, {
22
22
  default: () => createApp
@@ -1,14 +1,6 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- */
1
+ import type { Base, BaseConstructor, BaseTypeParameter } from '../Base/index.js';
4
2
  /**
5
3
  * Instantiate and mount the given component on the given root element when the page has been loaded
6
4
  * and return a function to use the app instance when it is ready.
7
- *
8
- * @template {BaseConstructor} T
9
- * @param {T} App
10
- * @param {HTMLElement} [rootElement]
11
- * @returns {() => Promise<InstanceType<T>>}
12
5
  */
13
- export default function createApp<T extends typeof import("../Base/index.js").default>(App: T, rootElement?: HTMLElement): () => Promise<InstanceType<T>>;
14
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
6
+ export default function createApp<S extends BaseConstructor<Base>, T extends BaseTypeParameter = BaseTypeParameter>(App: S, rootElement?: HTMLElement): () => Promise<S & Base<T>>;
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/getDirectChildren.js
19
+ // packages/js-toolkit/helpers/getDirectChildren.ts
20
20
  var getDirectChildren_exports = {};
21
21
  __export(getDirectChildren_exports, {
22
22
  getDirectChildren: () => getDirectChildren,
@@ -33,12 +33,12 @@ function getDirectChildren(parentInstance, parentName, childrenName) {
33
33
  if (!(0, import_utils.isArray)(nestedParents) || nestedParents.length <= 0) {
34
34
  return children;
35
35
  }
36
- return children.filter((child) => {
37
- return nestedParents.every((nestedParent) => {
36
+ return [...children].filter(
37
+ (child) => [...nestedParents].every((nestedParent) => {
38
38
  const nestedChildren = nestedParent.$children[childrenName];
39
39
  return (0, import_utils.isArray)(nestedChildren) ? !nestedChildren.includes(child) : true;
40
- });
41
- });
40
+ })
41
+ );
42
42
  }
43
43
  function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
44
44
  return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
@@ -1,6 +1,4 @@
1
- /**
2
- * @typedef {import('../Base/index.js').default} Base
3
- */
1
+ import { Base } from '../Base/index.js';
4
2
  /**
5
3
  * Get direct children from a parent when working with nested components.
6
4
  *
@@ -10,7 +8,7 @@
10
8
  * @param {string} childrenName
11
9
  * @returns {T[]}
12
10
  */
13
- export function getDirectChildren<T extends import("../Base/index.js").default<import("../Base/index.js").BaseTypeParameter>>(parentInstance: Base, parentName: string, childrenName: string): T[];
11
+ export declare function getDirectChildren<T extends Base = Base>(parentInstance: Base, parentName: string, childrenName: string): T[];
14
12
  /**
15
13
  * Test if a component instance is a direct child from the given component.
16
14
  *
@@ -20,5 +18,4 @@ export function getDirectChildren<T extends import("../Base/index.js").default<i
20
18
  * @param {Base} childInstance
21
19
  * @returns {boolean}
22
20
  */
23
- export function isDirectChild(parentInstance: Base, parentName: string, childrenName: string, childInstance: Base): boolean;
24
- export type Base = import('../Base/index.js').default;
21
+ export declare function isDirectChild(parentInstance: any, parentName: any, childrenName: any, childInstance: any): boolean;
@@ -8,12 +8,12 @@ function getDirectChildren(parentInstance, parentName, childrenName) {
8
8
  if (!isArray(nestedParents) || nestedParents.length <= 0) {
9
9
  return children;
10
10
  }
11
- return children.filter((child) => {
12
- return nestedParents.every((nestedParent) => {
11
+ return [...children].filter(
12
+ (child) => [...nestedParents].every((nestedParent) => {
13
13
  const nestedChildren = nestedParent.$children[childrenName];
14
14
  return isArray(nestedChildren) ? !nestedChildren.includes(child) : true;
15
- });
16
- });
15
+ })
16
+ );
17
17
  }
18
18
  function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
19
19
  return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
@@ -16,17 +16,16 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/getInstanceFromElement.js
19
+ // packages/js-toolkit/helpers/getInstanceFromElement.ts
20
20
  var getInstanceFromElement_exports = {};
21
21
  __export(getInstanceFromElement_exports, {
22
22
  default: () => getInstanceFromElement
23
23
  });
24
24
  module.exports = __toCommonJS(getInstanceFromElement_exports);
25
25
  function getInstanceFromElement(element, Constructor) {
26
- var _a;
27
- if (!element.__base__) {
26
+ if (!element.__base__ || !element.__base__.has(Constructor)) {
28
27
  return null;
29
28
  }
30
- return (_a = element.__base__.get(Constructor)) != null ? _a : null;
29
+ return element.__base__.get(Constructor);
31
30
  }
32
31
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,14 +1,5 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- */
1
+ import type { BaseConstructor, BaseEl } from '../Base/index.js';
4
2
  /**
5
3
  * Get a component instance from a DOM element.
6
- * @template {BaseConstructor} T
7
- * @param {HTMLElement & { __base__?: WeakMap<T, InstanceType<T>> }} element
8
- * @param {T} Constructor
9
- * @returns {null|InstanceType<T>}
10
4
  */
11
- export default function getInstanceFromElement<T extends typeof import("../Base/index.js").default>(element: HTMLElement & {
12
- __base__?: WeakMap<T, InstanceType<T>>;
13
- }, Constructor: T): InstanceType<T>;
14
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
5
+ export default function getInstanceFromElement<T extends BaseConstructor>(element: BaseEl, Constructor: T): InstanceType<T> | null;
@@ -1,9 +1,8 @@
1
1
  function getInstanceFromElement(element, Constructor) {
2
- var _a;
3
- if (!element.__base__) {
2
+ if (!element.__base__ || !element.__base__.has(Constructor)) {
4
3
  return null;
5
4
  }
6
- return (_a = element.__base__.get(Constructor)) != null ? _a : null;
5
+ return element.__base__.get(Constructor);
7
6
  }
8
7
  export {
9
8
  getInstanceFromElement as default
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/importOnInteraction.js
19
+ // packages/js-toolkit/helpers/importOnInteraction.ts
20
20
  var importOnInteraction_exports = {};
21
21
  __export(importOnInteraction_exports, {
22
22
  default: () => importOnInteraction
@@ -1,11 +1,8 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- * @typedef {import('../Base/index.js').default} Base
4
- */
1
+ import type { Base, BaseConstructor } from '../Base/index.js';
5
2
  /**
6
3
  * Import a component on an interaction.
7
4
  *
8
- * @template {BaseConstructor} T
5
+ * @template {BaseConstructor} [T=BaseConstructor]
9
6
  * @param {() => Promise<T|{default:T}>} fn
10
7
  * The import function.
11
8
  * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement
@@ -14,10 +11,8 @@
14
11
  * The events to listen to to trigger the import.
15
12
  * @param {Base} [parent]
16
13
  * The parent component.
17
- * @returns {Promise<T>}
14
+ * @returns {Promise<InstanceType<T>>}
18
15
  */
19
- export default function importOnInteraction<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
16
+ export default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
20
17
  default: T;
21
18
  }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], events: string | string[], parent?: Base): Promise<T>;
22
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
23
- export type Base = import('../Base/index.js').default;
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/importWhenIdle.js
19
+ // packages/js-toolkit/helpers/importWhenIdle.ts
20
20
  var importWhenIdle_exports = {};
21
21
  __export(importWhenIdle_exports, {
22
22
  default: () => importWhenIdle
23
23
  });
24
24
  module.exports = __toCommonJS(importWhenIdle_exports);
25
- function importWhenIdle(fn, options) {
25
+ function importWhenIdle(fn, { timeout = 1 } = {}) {
26
26
  let ResolvedClass;
27
27
  const resolver = (resolve) => {
28
28
  fn().then((module2) => {
@@ -31,8 +31,6 @@ function importWhenIdle(fn, options) {
31
31
  });
32
32
  };
33
33
  return new Promise((resolve) => {
34
- var _a;
35
- const timeout = (_a = options == null ? void 0 : options.timeout) != null ? _a : 1;
36
34
  if (!("requestIdleCallback" in window)) {
37
35
  setTimeout(() => {
38
36
  resolver(resolve);
@@ -44,7 +42,7 @@ function importWhenIdle(fn, options) {
44
42
  resolver(resolve);
45
43
  }, 0);
46
44
  },
47
- { timeout: options == null ? void 0 : options.timeout }
45
+ { timeout }
48
46
  );
49
47
  }
50
48
  });
@@ -1,7 +1,7 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- * @typedef {{ timeout?: number }} ImportWhenIdleOptions
4
- */
1
+ import type { BaseConstructor } from '../Base/index.js';
2
+ declare type ImportWhenIdleOptions = {
3
+ timeout?: number;
4
+ };
5
5
  /**
6
6
  * Import a component when user is idle.
7
7
  *
@@ -12,10 +12,7 @@
12
12
  * The time to wait before triggering the callback if never idle.
13
13
  * @returns {Promise<T>}
14
14
  */
15
- export default function importWhenIdle<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
15
+ export default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
16
16
  default: T;
17
- }>, options?: ImportWhenIdleOptions): Promise<T>;
18
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
19
- export type ImportWhenIdleOptions = {
20
- timeout?: number;
21
- };
17
+ }>, { timeout }?: ImportWhenIdleOptions): Promise<T>;
18
+ export {};
@@ -1,4 +1,4 @@
1
- function importWhenIdle(fn, options) {
1
+ function importWhenIdle(fn, { timeout = 1 } = {}) {
2
2
  let ResolvedClass;
3
3
  const resolver = (resolve) => {
4
4
  fn().then((module) => {
@@ -7,8 +7,6 @@ function importWhenIdle(fn, options) {
7
7
  });
8
8
  };
9
9
  return new Promise((resolve) => {
10
- var _a;
11
- const timeout = (_a = options == null ? void 0 : options.timeout) != null ? _a : 1;
12
10
  if (!("requestIdleCallback" in window)) {
13
11
  setTimeout(() => {
14
12
  resolver(resolve);
@@ -20,7 +18,7 @@ function importWhenIdle(fn, options) {
20
18
  resolver(resolve);
21
19
  }, 0);
22
20
  },
23
- { timeout: options == null ? void 0 : options.timeout }
21
+ { timeout }
24
22
  );
25
23
  }
26
24
  });
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/importWhenVisible.js
19
+ // packages/js-toolkit/helpers/importWhenVisible.ts
20
20
  var importWhenVisible_exports = {};
21
21
  __export(importWhenVisible_exports, {
22
22
  default: () => importWhenVisible
@@ -1,7 +1,4 @@
1
- /**
2
- * @typedef {import('../Base/index.js').default} Base
3
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
4
- */
1
+ import type { Base, BaseConstructor } from '../Base/index.js';
5
2
  /**
6
3
  * Import a component when it is visible.
7
4
  *
@@ -16,8 +13,6 @@
16
13
  * Options for the `IntersectionObserver` instance.
17
14
  * @returns {Promise<T>}
18
15
  */
19
- export default function importWhenVisible<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
16
+ export default function importWhenVisible<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
20
17
  default: T;
21
18
  }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], parent?: Base, observerOptions?: IntersectionObserverInit): Promise<T>;
22
- export type Base = import('../Base/index.js').default;
23
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
package/helpers/index.cjs CHANGED
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  ));
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
 
26
- // packages/js-toolkit/helpers/index.js
26
+ // packages/js-toolkit/helpers/index.ts
27
27
  var helpers_exports = {};
28
28
  __export(helpers_exports, {
29
29
  createApp: () => import_createApp.default,
@@ -1,6 +1,6 @@
1
- export { default as createApp } from "./createApp.js";
2
- export * from "./getDirectChildren.js";
3
- export { default as getInstanceFromElement } from "./getInstanceFromElement.js";
4
- export { default as importOnInteraction } from "./importOnInteraction.js";
5
- export { default as importWhenIdle } from "./importWhenIdle.js";
6
- export { default as importWhenVisible } from "./importWhenVisible.js";
1
+ export { default as createApp } from './createApp.js';
2
+ export * from './getDirectChildren.js';
3
+ export { default as getInstanceFromElement } from './getInstanceFromElement.js';
4
+ export { default as importOnInteraction } from './importOnInteraction.js';
5
+ export { default as importWhenIdle } from './importWhenIdle.js';
6
+ export { default as importWhenVisible } from './importWhenVisible.js';
package/helpers/utils.cjs CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/utils.js
19
+ // packages/js-toolkit/helpers/utils.ts
20
20
  var utils_exports = {};
21
21
  __export(utils_exports, {
22
22
  getTargetElements: () => getTargetElements
@@ -7,4 +7,4 @@
7
7
  * The optional context to use to query for elements.
8
8
  * @returns {HTMLElement[]} A normalized list of elements.
9
9
  */
10
- export function getTargetElements(nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], context?: HTMLElement): HTMLElement[];
10
+ export declare function getTargetElements(nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], context: HTMLElement): HTMLElement[];
package/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -17,19 +15,15 @@ var __copyProps = (to, from, except, desc) => {
17
15
  return to;
18
16
  };
19
17
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
 
26
20
  // packages/js-toolkit/index.ts
27
21
  var js_toolkit_exports = {};
28
22
  __export(js_toolkit_exports, {
29
- Base: () => import_Base.default
23
+ Base: () => import_Base.Base
30
24
  });
31
25
  module.exports = __toCommonJS(js_toolkit_exports);
32
- var import_Base = __toESM(require("./Base/index.cjs"), 1);
26
+ var import_Base = require("./Base/index.cjs");
33
27
  __reExport(js_toolkit_exports, require("./decorators/index.cjs"), module.exports);
34
28
  __reExport(js_toolkit_exports, require("./helpers/index.cjs"), module.exports);
35
29
  __reExport(js_toolkit_exports, require("./services/index.cjs"), module.exports);
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { default as Base } from './Base/index.js';
1
+ export { Base } from './Base/index.js';
2
2
  export * from './decorators/index.js';
3
3
  export * from './helpers/index.js';
4
4
  export * from './services/index.js';
5
5
  export type { BaseTypeParameter, BaseConstructor, BaseAsyncConstructor, BaseConfig, } from './Base/index.js';
6
- export type { BaseInterface } from './Base/types.js';
6
+ export type { BaseInterface, } from './Base/types.js';
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { default as default2 } from "./Base/index.js";
1
+ import { Base } from "./Base/index.js";
2
2
  export * from "./decorators/index.js";
3
3
  export * from "./helpers/index.js";
4
4
  export * from "./services/index.js";
5
5
  export {
6
- default2 as Base
6
+ Base
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/js-toolkit",
3
- "version": "2.4.4-alpha.3",
3
+ "version": "2.4.4-alpha.6",
4
4
  "description": "A set of useful little bits of JavaScript to boost your project! 🚀",
5
5
  "publishConfig": {
6
6
  "access": "public"