@studiometa/js-toolkit 2.4.4-alpha.0 → 2.4.4-alpha.1

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 (42) hide show
  1. package/Base/index.d.ts +336 -0
  2. package/Base/managers/AbstractManager.d.ts +44 -0
  3. package/Base/managers/ChildrenManager.d.ts +41 -0
  4. package/Base/managers/EventsManager.d.ts +112 -0
  5. package/Base/managers/OptionsManager.d.ts +87 -0
  6. package/Base/managers/RefsManager.d.ts +32 -0
  7. package/Base/managers/ResponsiveOptionsManager.cjs +1 -1
  8. package/Base/managers/ResponsiveOptionsManager.d.ts +22 -0
  9. package/Base/managers/ServicesManager.d.ts +109 -0
  10. package/Base/utils.d.ts +40 -0
  11. package/decorators/index.d.ts +10 -0
  12. package/decorators/withBreakpointManager.d.ts +87 -0
  13. package/decorators/withBreakpointObserver.d.ts +93 -0
  14. package/decorators/withDrag.d.ts +84 -0
  15. package/decorators/withExtraConfig.d.ts +85 -0
  16. package/decorators/withFreezedOptions.d.ts +84 -0
  17. package/decorators/withIntersectionObserver.d.ts +97 -0
  18. package/decorators/withMountWhenInView.d.ts +95 -0
  19. package/decorators/withResponsiveOptions.d.ts +81 -0
  20. package/decorators/withScrolledInView.d.ts +198 -0
  21. package/decorators/withVue2.cjs +2 -2
  22. package/decorators/withVue2.d.ts +98 -0
  23. package/decorators/withVue2.js +2 -2
  24. package/helpers/createApp.d.ts +14 -0
  25. package/helpers/getDirectChildren.d.ts +31 -0
  26. package/helpers/getInstanceFromElement.d.ts +14 -0
  27. package/helpers/importOnInteraction.d.ts +23 -0
  28. package/helpers/importWhenIdle.d.ts +21 -0
  29. package/helpers/importWhenVisible.d.ts +23 -0
  30. package/helpers/index.d.ts +6 -0
  31. package/helpers/utils.d.ts +10 -0
  32. package/index.d.ts +5 -0
  33. package/package.json +1 -1
  34. package/services/drag.d.ts +1 -1
  35. package/services/index.cjs +1 -1
  36. package/services/index.d.ts +33 -25
  37. package/services/key.d.ts +1 -1
  38. package/services/load.d.ts +1 -1
  39. package/services/pointer.d.ts +1 -1
  40. package/services/raf.d.ts +1 -1
  41. package/services/resize.d.ts +1 -1
  42. package/services/scroll.d.ts +1 -1
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
+ */
4
+ /**
5
+ * 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
+ */
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;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
+ * @typedef {import('../Base/index.js').default} Base
4
+ */
5
+ /**
6
+ * Import a component on an interaction.
7
+ *
8
+ * @template {BaseConstructor} T
9
+ * @param {() => Promise<T|{default:T}>} fn
10
+ * The import function.
11
+ * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement
12
+ * The name or selector for the component.
13
+ * @param {string|string[]} events
14
+ * The events to listen to to trigger the import.
15
+ * @param {Base} [parent]
16
+ * The parent component.
17
+ * @returns {Promise<T>}
18
+ */
19
+ export default function importOnInteraction<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
20
+ default: T;
21
+ }>, 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;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
+ * @typedef {{ timeout?: number }} ImportWhenIdleOptions
4
+ */
5
+ /**
6
+ * Import a component when user is idle.
7
+ *
8
+ * @template {BaseConstructor} T
9
+ * @param {() => Promise<T|{default:T}>} fn
10
+ * The import function.
11
+ * @param {ImportWhenIdleOptions} [options]
12
+ * The time to wait before triggering the callback if never idle.
13
+ * @returns {Promise<T>}
14
+ */
15
+ export default function importWhenIdle<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
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
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @typedef {import('../Base/index.js').default} Base
3
+ * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
4
+ */
5
+ /**
6
+ * Import a component when it is visible.
7
+ *
8
+ * @template {BaseConstructor} T
9
+ * @param {() => Promise<T|{default:T}>} fn
10
+ * The import function.
11
+ * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement
12
+ * The name or selector for the component.
13
+ * @param {Base} [parent]
14
+ * The parent component.
15
+ * @param {IntersectionObserverInit} [observerOptions]
16
+ * Options for the `IntersectionObserver` instance.
17
+ * @returns {Promise<T>}
18
+ */
19
+ export default function importWhenVisible<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
20
+ default: T;
21
+ }>, 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;
@@ -0,0 +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";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Get the target elements for the lazy import helper functions.
3
+ *
4
+ * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement
5
+ * The original selector or element, or list of elements.
6
+ * @param {HTMLElement} [context]
7
+ * The optional context to use to query for elements.
8
+ * @returns {HTMLElement[]} A normalized list of elements.
9
+ */
10
+ export function getTargetElements(nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], context?: HTMLElement): HTMLElement[];
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { default as Base } from './Base/index.js';
2
+ export * from './decorators/index.js';
3
+ export * from './helpers/index.js';
4
+ export * from './services/index.js';
5
+ export type { BaseTypeParameter, BaseConstructor, BaseAsyncConstructor, BaseConfig, } from './Base/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/js-toolkit",
3
- "version": "2.4.4-alpha.0",
3
+ "version": "2.4.4-alpha.1",
4
4
  "description": "A set of useful little bits of JavaScript to boost your project! 🚀",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,7 +14,7 @@
14
14
  * @param {DragServiceOptions} options
15
15
  * @returns {DragService}
16
16
  */
17
- export default function useDrag(target: HTMLElement, options: DragServiceOptions): DragService;
17
+ export default function useDrag(target: HTMLElement, options: DragServiceOptions): import("./index").ServiceInterface<DragServiceProps>;
18
18
  export type DragService = import('./index').ServiceInterface<DragServiceProps>;
19
19
  export type PointerServiceProps = import('./pointer.js').PointerServiceProps;
20
20
  export type DragLifecycle = 'start' | 'drag' | 'drop' | 'inertia' | 'stop';
@@ -22,7 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  ));
23
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
24
 
25
- // packages/js-toolkit/services/index.js
25
+ // packages/js-toolkit/services/index.ts
26
26
  var services_exports = {};
27
27
  __export(services_exports, {
28
28
  useDrag: () => import_drag.default,
@@ -1,33 +1,41 @@
1
- export { default as useDrag } from "./drag.js";
2
- export { default as useKey } from "./key.js";
3
- export { default as useLoad } from "./load.js";
4
- export { default as usePointer } from "./pointer.js";
5
- export { default as useRaf } from "./raf.js";
6
- export { default as useResize } from "./resize.js";
7
- export { default as useScroll } from "./scroll.js";
8
- export { useService } from "./service.js";
9
- export type ServiceInterface<T> = {
1
+ import type { DragServiceProps } from './drag.js';
2
+ import type { KeyServiceProps } from './key.js';
3
+ import type { LoadServiceProps } from './load.js';
4
+ import type { PointerServiceProps } from './pointer.js';
5
+ import type { RafServiceProps } from './raf.js';
6
+ import type { ResizeServiceProps } from './resize.js';
7
+ import type { ScrollServiceProps } from './scroll.js';
8
+ export interface ServiceInterface<T> {
10
9
  /**
11
- * Remove a function from the resize service by its key.
10
+ * Remove a function from the resize service by its key.
12
11
  */
13
- remove: (key: string) => void;
12
+ remove(key: string): void;
14
13
  /**
15
- * Add a callback to the service. The callback will receive the current service props as parameter.
14
+ * Add a callback to the service. The callback will receive the current service props as parameter.
16
15
  */
17
- add: (key: string, cb: (props: T) => void) => void;
16
+ add(key: string, callback: (props: T) => void): void;
18
17
  /**
19
- * Test if the service has alreaydy a callback for the given key.
18
+ * Test if the service has alreaydy a callback for the given key.
20
19
  */
21
- has: (key: string) => boolean;
20
+ has(key: string): boolean;
22
21
  /**
23
- * Get the service's props.
22
+ * Get the service's props.
24
23
  */
25
- props: () => T;
26
- };
27
- export type DragServiceProps = import('./drag').DragServiceProps;
28
- export type KeyServiceProps = import('./key').KeyServiceProps;
29
- export type LoadServiceProps = import('./load').LoadServiceProps;
30
- export type PointerServiceProps = import('./pointer').PointerServiceProps;
31
- export type RafServiceProps = import('./raf').RafServiceProps;
32
- export type ResizeServiceProps = import('./resize').ResizeServiceProps;
33
- export type ScrollServiceProps = import('./scroll').ScrollServiceProps;
24
+ props(): T;
25
+ }
26
+ export declare type DragServiceInterface = ServiceInterface<DragServiceProps>;
27
+ export declare type KeyServiceInterface = ServiceInterface<KeyServiceProps>;
28
+ export declare type LoadServiceInterface = ServiceInterface<LoadServiceProps>;
29
+ export declare type PointerServiceInterface = ServiceInterface<PointerServiceProps>;
30
+ export declare type RafServiceInterface = ServiceInterface<RafServiceProps>;
31
+ export declare type ResizeServiceInterface = ServiceInterface<ResizeServiceProps>;
32
+ export declare type ScrollServiceInterface = ServiceInterface<ScrollServiceProps>;
33
+ export type { DragServiceProps, KeyServiceProps, LoadServiceProps, PointerServiceProps, RafServiceProps, ResizeServiceProps, ScrollServiceProps, };
34
+ export { default as useDrag } from './drag.js';
35
+ export { default as useKey } from './key.js';
36
+ export { default as useLoad } from './load.js';
37
+ export { default as usePointer } from './pointer.js';
38
+ export { default as useRaf } from './raf.js';
39
+ export { default as useResize } from './resize.js';
40
+ export { default as useScroll } from './scroll.js';
41
+ export { useService } from './service.js';
package/services/key.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns {KeyService}
5
5
  */
6
- export default function useKey(): KeyService;
6
+ export default function useKey(): import("./index").ServiceInterface<KeyServiceProps>;
7
7
  export type KeyService = import('./index').ServiceInterface<KeyServiceProps>;
8
8
  export type KeyServiceProps = {
9
9
  event: KeyboardEvent;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns {LoadService}
5
5
  */
6
- export default function useLoad(): LoadService;
6
+ export default function useLoad(): import("./index").ServiceInterface<LoadServiceProps>;
7
7
  export type LoadService = import('./index').ServiceInterface<LoadServiceProps>;
8
8
  export type LoadServiceProps = {
9
9
  time: DOMHighResTimeStamp;
@@ -4,7 +4,7 @@
4
4
  * @todo Add element as parameter to get the pointer position relatively from.
5
5
  * @returns {PointerService}
6
6
  */
7
- export default function usePointer(): PointerService;
7
+ export default function usePointer(): import("./index").ServiceInterface<PointerServiceProps>;
8
8
  export type PointerService = import('./index').ServiceInterface<PointerServiceProps>;
9
9
  export type PointerServiceProps = {
10
10
  event: MouseEvent | TouchEvent;
package/services/raf.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns {RafService}
5
5
  */
6
- export default function useRaf(): RafService;
6
+ export default function useRaf(): import("./index").ServiceInterface<RafServiceProps>;
7
7
  export type RafService = import('./index').ServiceInterface<RafServiceProps>;
8
8
  export type RafServiceProps = {
9
9
  time: DOMHighResTimeStamp;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns {ResizeService}
5
5
  */
6
- export default function useResize(): ResizeService;
6
+ export default function useResize(): import("./index").ServiceInterface<ResizeServiceProps>;
7
7
  export type ResizeService = import('./index').ServiceInterface<ResizeServiceProps>;
8
8
  export type ResizeServiceProps = {
9
9
  width: number;
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @returns {ScrollService}
13
13
  */
14
- export default function useScroll(): ScrollService;
14
+ export default function useScroll(): import("./index").ServiceInterface<ScrollServiceProps>;
15
15
  export type ScrollService = import('./index').ServiceInterface<ScrollServiceProps>;
16
16
  export type ScrollServiceProps = {
17
17
  x: number;