@studiometa/js-toolkit 3.5.0 → 3.6.0-beta.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.
- package/Base/Base.d.ts +2 -2
- package/Base/Base.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +2 -2
- package/Base/types.d.ts +3 -3
- package/Base/utils.d.ts +1 -1
- package/Base/utils.js +1 -2
- package/Base/utils.js.map +2 -2
- package/README.md +10 -0
- package/decorators/withBreakpointManager.d.ts +1 -1
- package/decorators/withBreakpointManager.js.map +1 -1
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js.map +1 -1
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withDrag.js.map +1 -1
- package/decorators/withExtraConfig.d.ts +1 -1
- package/decorators/withExtraConfig.js.map +1 -1
- package/decorators/withFreezedOptions.d.ts +1 -1
- package/decorators/withFreezedOptions.js.map +1 -1
- package/decorators/withGroup.js.map +2 -2
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js.map +1 -1
- package/decorators/withMountOnMediaQuery.d.ts +1 -1
- package/decorators/withMountOnMediaQuery.js.map +1 -1
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js.map +1 -1
- package/decorators/withMutation.d.ts +1 -1
- package/decorators/withMutation.js.map +1 -1
- package/decorators/withRelativePointer.d.ts +1 -1
- package/decorators/withRelativePointer.js.map +1 -1
- package/decorators/withResponsiveOptions.d.ts +1 -1
- package/decorators/withResponsiveOptions.js.map +1 -1
- package/decorators/withScrolledInView/withScrolledInView.d.ts +1 -1
- package/decorators/withScrolledInView/withScrolledInView.js.map +1 -1
- package/helpers/createApp.d.ts +1 -1
- package/helpers/createApp.js +6 -4
- package/helpers/createApp.js.map +2 -2
- package/helpers/getClosestParent.d.ts +1 -1
- package/helpers/getClosestParent.js.map +1 -1
- package/helpers/getDirectChildren.d.ts +2 -2
- package/helpers/getDirectChildren.js.map +1 -1
- package/helpers/getInstanceFromElement.d.ts +1 -1
- package/helpers/getInstanceFromElement.js.map +1 -1
- package/helpers/importOnInteraction.d.ts +1 -1
- package/helpers/importOnInteraction.js.map +1 -1
- package/helpers/importOnMediaQuery.d.ts +1 -1
- package/helpers/importOnMediaQuery.js.map +1 -1
- package/helpers/importWhenIdle.d.ts +1 -1
- package/helpers/importWhenIdle.js.map +1 -1
- package/helpers/importWhenPrefersMotion.d.ts +1 -1
- package/helpers/importWhenPrefersMotion.js.map +1 -1
- package/helpers/importWhenVisible.d.ts +1 -1
- package/helpers/importWhenVisible.js.map +1 -1
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +1 -0
- package/helpers/index.js.map +2 -2
- package/helpers/logTree.d.ts +17 -0
- package/helpers/logTree.js +59 -0
- package/helpers/logTree.js.map +7 -0
- package/helpers/queryComponent.js +9 -10
- package/helpers/queryComponent.js.map +2 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/services/AbstractService.d.ts +1 -1
- package/services/AbstractService.js +1 -1
- package/services/AbstractService.js.map +2 -2
- package/services/DragService.d.ts +6 -6
- package/services/DragService.js.map +1 -1
- package/services/KeyService.d.ts +1 -1
- package/services/KeyService.js.map +1 -1
- package/services/LoadService.d.ts +1 -1
- package/services/LoadService.js.map +1 -1
- package/services/MutationService.d.ts +1 -1
- package/services/MutationService.js.map +1 -1
- package/services/PointerService.d.ts +1 -1
- package/services/PointerService.js.map +1 -1
- package/services/RafService.d.ts +2 -2
- package/services/RafService.js +13 -7
- package/services/RafService.js.map +2 -2
- package/services/ResizeService.d.ts +1 -1
- package/services/ResizeService.js.map +1 -1
- package/services/ScrollService.d.ts +22 -4
- package/services/ScrollService.js +55 -7
- package/services/ScrollService.js.map +2 -2
- package/utils/cache.d.ts +1 -1
- package/utils/cache.js.map +1 -1
- package/utils/collide/boundingRectToCircle.d.ts +3 -3
- package/utils/collide/boundingRectToCircle.js.map +1 -1
- package/utils/collide/collideCircleCircle.d.ts +1 -1
- package/utils/collide/collideCircleCircle.js.map +1 -1
- package/utils/collide/collideCircleRect.d.ts +1 -1
- package/utils/collide/collideCircleRect.js.map +1 -1
- package/utils/collide/collidePointCircle.d.ts +1 -1
- package/utils/collide/collidePointCircle.js.map +1 -1
- package/utils/collide/collidePointRect.d.ts +1 -1
- package/utils/collide/collidePointRect.js.map +1 -1
- package/utils/collide/collideRectRect.d.ts +1 -1
- package/utils/collide/collideRectRect.js.map +1 -1
- package/utils/css/animate.d.ts +1 -1
- package/utils/css/animate.js +162 -96
- package/utils/css/animate.js.map +2 -2
- package/utils/css/classes.d.ts +3 -3
- package/utils/css/classes.js.map +1 -1
- package/utils/css/getOffsetSizes.d.ts +1 -1
- package/utils/css/getOffsetSizes.js.map +1 -1
- package/utils/css/matrix.d.ts +1 -1
- package/utils/css/matrix.js.map +1 -1
- package/utils/css/styles.d.ts +2 -2
- package/utils/css/styles.js.map +1 -1
- package/utils/css/transform.d.ts +1 -1
- package/utils/css/transform.js +12 -13
- package/utils/css/transform.js.map +2 -2
- package/utils/css/transition.d.ts +1 -1
- package/utils/css/transition.js.map +1 -1
- package/utils/debounce.d.ts +1 -1
- package/utils/debounce.js.map +1 -1
- package/utils/history.d.ts +3 -3
- package/utils/history.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/index.js.map +2 -2
- package/utils/is.d.ts +10 -10
- package/utils/is.js.map +1 -1
- package/utils/loadElement.d.ts +5 -5
- package/utils/loadElement.js.map +1 -1
- package/utils/math/clamp.d.ts +1 -1
- package/utils/math/clamp.js.map +1 -1
- package/utils/math/clamp01.d.ts +1 -1
- package/utils/math/clamp01.js.map +1 -1
- package/utils/math/createEases.d.ts +2 -2
- package/utils/math/createEases.js.map +1 -1
- package/utils/math/createRange.d.ts +1 -1
- package/utils/math/createRange.js.map +1 -1
- package/utils/math/damp.d.ts +1 -1
- package/utils/math/damp.js.map +2 -2
- package/utils/math/inertiaFinalValue.d.ts +1 -1
- package/utils/math/inertiaFinalValue.js.map +1 -1
- package/utils/math/lerp.d.ts +1 -1
- package/utils/math/lerp.js.map +1 -1
- package/utils/math/map.d.ts +1 -1
- package/utils/math/map.js.map +1 -1
- package/utils/math/round.d.ts +1 -1
- package/utils/math/round.js.map +1 -1
- package/utils/math/smoothTo.d.ts +24 -6
- package/utils/math/wrap.d.ts +1 -1
- package/utils/math/wrap.js.map +1 -1
- package/utils/memo.d.ts +1 -1
- package/utils/memo.js.map +1 -1
- package/utils/memoize.d.ts +2 -2
- package/utils/memoize.js.map +1 -1
- package/utils/nextFrame.d.ts +1 -1
- package/utils/nextFrame.js.map +1 -1
- package/utils/nextMicrotask.d.ts +1 -1
- package/utils/nextMicrotask.js.map +1 -1
- package/utils/nextTick.d.ts +1 -1
- package/utils/nextTick.js.map +1 -1
- package/utils/object/getAllProperties.js +4 -2
- package/utils/object/getAllProperties.js.map +2 -2
- package/utils/random.d.ts +3 -3
- package/utils/random.js.map +1 -1
- package/utils/scheduler.d.ts +3 -3
- package/utils/scheduler.js.map +1 -1
- package/utils/scrollTo.d.ts +1 -1
- package/utils/scrollTo.js.map +1 -1
- package/utils/storage/createLocalStorageProvider.d.ts +2 -0
- package/utils/storage/createLocalStorageProvider.js +32 -0
- package/utils/storage/createLocalStorageProvider.js.map +7 -0
- package/utils/storage/createMemoryStorageProvider.d.ts +2 -0
- package/utils/storage/createMemoryStorageProvider.js +27 -0
- package/utils/storage/createMemoryStorageProvider.js.map +7 -0
- package/utils/storage/createNoopProvider.d.ts +2 -0
- package/utils/storage/createNoopProvider.js +23 -0
- package/utils/storage/createNoopProvider.js.map +7 -0
- package/utils/storage/createSessionStorageProvider.d.ts +2 -0
- package/utils/storage/createSessionStorageProvider.js +31 -0
- package/utils/storage/createSessionStorageProvider.js.map +7 -0
- package/utils/storage/createStorage.d.ts +2 -0
- package/utils/storage/createStorage.js +96 -0
- package/utils/storage/createStorage.js.map +7 -0
- package/utils/storage/createUrlSearchParamsInHashProvider.d.ts +2 -0
- package/utils/storage/createUrlSearchParamsInHashProvider.js +57 -0
- package/utils/storage/createUrlSearchParamsInHashProvider.js.map +7 -0
- package/utils/storage/createUrlSearchParamsProvider.d.ts +2 -0
- package/utils/storage/createUrlSearchParamsProvider.js +41 -0
- package/utils/storage/createUrlSearchParamsProvider.js.map +7 -0
- package/utils/storage/getBrowserContext.d.ts +1 -0
- package/utils/storage/getBrowserContext.js +17 -0
- package/utils/storage/getBrowserContext.js.map +7 -0
- package/utils/storage/getGlobalStorage.d.ts +1 -0
- package/utils/storage/getGlobalStorage.js +7 -0
- package/utils/storage/getGlobalStorage.js.map +7 -0
- package/utils/storage/getStorageKeys.d.ts +1 -0
- package/utils/storage/getStorageKeys.js +12 -0
- package/utils/storage/getStorageKeys.js.map +7 -0
- package/utils/storage/index.d.ts +8 -0
- package/utils/storage/index.js +62 -0
- package/utils/storage/index.js.map +7 -0
- package/utils/storage/providers.d.ts +11 -0
- package/utils/storage/providers.js +30 -0
- package/utils/storage/providers.js.map +7 -0
- package/utils/storage/serializers.d.ts +2 -0
- package/utils/storage/serializers.js +14 -0
- package/utils/storage/serializers.js.map +7 -0
- package/utils/storage/types.d.ts +33 -0
- package/utils/storage/types.js +1 -0
- package/utils/storage/types.js.map +7 -0
- package/utils/storage.d.ts +1 -0
- package/utils/storage.js +2 -0
- package/utils/storage.js.map +7 -0
- package/utils/string/changeCase.d.ts +6 -6
- package/utils/string/changeCase.js +1 -1
- package/utils/string/changeCase.js.map +2 -2
- package/utils/string/withLeadingCharacters.d.ts +1 -1
- package/utils/string/withLeadingCharacters.js.map +1 -1
- package/utils/string/withLeadingSlash.d.ts +1 -1
- package/utils/string/withLeadingSlash.js.map +1 -1
- package/utils/string/withTrailingCharacters.d.ts +1 -1
- package/utils/string/withTrailingCharacters.js.map +1 -1
- package/utils/string/withTrailingSlash.d.ts +1 -1
- package/utils/string/withTrailingSlash.js.map +1 -1
- package/utils/string/withoutLeadingCharacters.d.ts +1 -1
- package/utils/string/withoutLeadingCharacters.js.map +1 -1
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +1 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +1 -1
- package/utils/string/withoutLeadingSlash.d.ts +1 -1
- package/utils/string/withoutLeadingSlash.js.map +1 -1
- package/utils/string/withoutTrailingCharacters.d.ts +1 -1
- package/utils/string/withoutTrailingCharacters.js.map +1 -1
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +1 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +1 -1
- package/utils/string/withoutTrailingSlash.d.ts +1 -1
- package/utils/string/withoutTrailingSlash.js.map +1 -1
- package/utils/throttle.d.ts +1 -1
- package/utils/throttle.js.map +1 -1
- package/utils/trapFocus.d.ts +2 -2
- package/utils/trapFocus.js.map +1 -1
- package/utils/tween.js +5 -5
- package/utils/tween.js.map +2 -2
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMutation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { MutationServiceOptions, MutationServiceProps } from '../services/index.js';\nimport { useMutation } from '../services/index.js';\n\nexport type MutationDecoratorOptions = MutationServiceOptions & {\n target?: (this: Base, instance: Base) => Node;\n};\n\nexport interface WithMutationInterface extends BaseInterface {\n mutated?(props: MutationServiceProps): void;\n}\n\n/**\n * Add a mutation observer to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withMutation.html\n*/\nexport function withMutation<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el, ...options }: MutationDecoratorOptions = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithMutation<T extends BaseProps = BaseProps> extends BaseClass<T & WithMutationInterface> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['mutated'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n this.$on('mounted', () => {\n this.$services.register(\n 'mutated',\n useMutation.bind(undefined, target.call(this, this), options),\n );\n this.$services.enable('mutated');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('mutated');\n this.$services.unregister('mutated');\n });\n }\n }\n\n // @ts-ignore\n return WithMutation;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { MutationServiceOptions, MutationServiceProps } from '../services/index.js';\nimport { useMutation } from '../services/index.js';\n\nexport type MutationDecoratorOptions = MutationServiceOptions & {\n target?: (this: Base, instance: Base) => Node;\n};\n\nexport interface WithMutationInterface extends BaseInterface {\n mutated?(props: MutationServiceProps): void;\n}\n\n/**\n * Add a mutation observer to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withMutation.html\n */\nexport function withMutation<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el, ...options }: MutationDecoratorOptions = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithMutation<T extends BaseProps = BaseProps> extends BaseClass<T & WithMutationInterface> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['mutated'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n this.$on('mounted', () => {\n this.$services.register(\n 'mutated',\n useMutation.bind(undefined, target.call(this, this), options),\n );\n this.$services.enable('mutated');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('mutated');\n this.$services.unregister('mutated');\n });\n }\n }\n\n // @ts-ignore\n return WithMutation;\n}\n"],
|
|
5
5
|
"mappings": "AAGA,SAAS,mBAAmB;AAcrB,SAAS,aACd,WACA,EAAE,SAAS,CAAC,aAAa,SAAS,KAAK,GAAG,QAAQ,IAA8B,CAAC,GAChD;AAAA,EAIjC,MAAM,qBAAsD,UAAqC;AAAA;AAAA;AAAA;AAAA,IAI/F,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,OAAO,CAAC,SAAS;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AACb,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU;AAAA,UACb;AAAA,UACA,YAAY,KAAK,QAAW,OAAO,KAAK,MAAM,IAAI,GAAG,OAAO;AAAA,QAC9D;AACA,aAAK,UAAU,OAAO,SAAS;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,QAAQ,SAAS;AAChC,aAAK,UAAU,WAAW,SAAS;AAAA,MACrC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,5 +10,5 @@ export interface RelativePointerInterface extends BaseInterface {
|
|
|
10
10
|
/**
|
|
11
11
|
* Add dragging capabilities to a component.
|
|
12
12
|
* @link https://js-toolkit.studiometa.dev/api/decorators/withRelativePointer.html
|
|
13
|
-
*/
|
|
13
|
+
*/
|
|
14
14
|
export declare function withRelativePointer<S extends Base>(BaseClass: typeof Base, { target }?: RelativePointerDecoratorOptions): BaseDecorator<RelativePointerInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withRelativePointer.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { PointerServiceProps } from '../services/index.js';\nimport { usePointer } from '../services/index.js';\n\nexport type RelativePointerDecoratorOptions = {\n target?: (this: Base, instance: Base) => HTMLElement;\n};\n\nexport interface RelativePointerInterface extends BaseInterface {\n movedrelative?(props: PointerServiceProps): void;\n}\n\n/**\n * Add dragging capabilities to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withRelativePointer.html\n*/\nexport function withRelativePointer<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el }: RelativePointerDecoratorOptions = {},\n): BaseDecorator<RelativePointerInterface, S> {\n /**\n * Class.\n */\n class WithRelativePointer<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['movedrelative'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$services.register(\n 'movedrelative',\n usePointer.bind(undefined, target.call(this, this)),\n );\n this.$services.enable('movedrelative');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('movedrelative');\n this.$services.unregister('movedrelative');\n });\n }\n }\n\n // @ts-ignore\n return WithRelativePointer;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { PointerServiceProps } from '../services/index.js';\nimport { usePointer } from '../services/index.js';\n\nexport type RelativePointerDecoratorOptions = {\n target?: (this: Base, instance: Base) => HTMLElement;\n};\n\nexport interface RelativePointerInterface extends BaseInterface {\n movedrelative?(props: PointerServiceProps): void;\n}\n\n/**\n * Add dragging capabilities to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withRelativePointer.html\n */\nexport function withRelativePointer<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el }: RelativePointerDecoratorOptions = {},\n): BaseDecorator<RelativePointerInterface, S> {\n /**\n * Class.\n */\n class WithRelativePointer<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['movedrelative'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$services.register(\n 'movedrelative',\n usePointer.bind(undefined, target.call(this, this)),\n );\n this.$services.enable('movedrelative');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('movedrelative');\n this.$services.unregister('movedrelative');\n });\n }\n }\n\n // @ts-ignore\n return WithRelativePointer;\n}\n"],
|
|
5
5
|
"mappings": "AAGA,SAAS,kBAAkB;AAcpB,SAAS,oBACd,WACA,EAAE,SAAS,CAAC,aAAa,SAAS,IAAI,IAAqC,CAAC,GAChC;AAAA,EAI5C,MAAM,4BAA6D,UAAa;AAAA;AAAA;AAAA;AAAA,IAI9E,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,OAAO,CAAC,eAAe;AAAA,IACzB;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU;AAAA,UACb;AAAA,UACA,WAAW,KAAK,QAAW,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,QACpD;AACA,aAAK,UAAU,OAAO,eAAe;AAAA,MACvC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,QAAQ,eAAe;AACtC,aAAK,UAAU,WAAW,eAAe;AAAA,MAC3C,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import type { Base } from '../Base/index.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Extends the configuration of an existing class.
|
|
5
5
|
* @link https://js-toolkit.studiometa.dev/api/decorators/withResponsiveOptions.html
|
|
6
|
-
*/
|
|
6
|
+
*/
|
|
7
7
|
export declare function withResponsiveOptions<S extends Base>(BaseClass: typeof Base, { responsiveOptions }?: {
|
|
8
8
|
responsiveOptions?: any[];
|
|
9
9
|
}): BaseDecorator<BaseInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withResponsiveOptions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, Managers } from '../Base/index.js';\nimport type { OptionObject, OptionType } from '../Base/managers/OptionsManager.js';\nimport {\n ResponsiveOptionsManager,\n ResponsiveOptionObject,\n} from '../Base/managers/ResponsiveOptionsManager.js';\nimport { isDefined, isObject } from '../utils/index.js';\n\n/**\n * Extends the configuration of an existing class.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withResponsiveOptions.html\n*/\nexport function withResponsiveOptions<S extends Base>(\n BaseClass: typeof Base,\n { responsiveOptions = [] } = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithResponsiveOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Configure responsive options.\n */\n get __config() {\n const config = super.__config;\n const options = config.options;\n\n for (const option of responsiveOptions) {\n if (isDefined(options[option])) {\n const oldOption = options[option];\n options[option] = {\n type: isObject(oldOption)\n ? (oldOption as OptionObject).type\n : (oldOption as OptionType),\n responsive: true,\n } as ResponsiveOptionObject;\n }\n }\n\n return config;\n }\n\n /**\n * Get managers.\n */\n get __managers(): Managers & { OptionsManager: typeof ResponsiveOptionsManager } {\n return {\n ...super.__managers,\n OptionsManager: ResponsiveOptionsManager,\n };\n }\n }\n\n // @ts-ignore\n return WithResponsiveOptions;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, Managers } from '../Base/index.js';\nimport type { OptionObject, OptionType } from '../Base/managers/OptionsManager.js';\nimport {\n ResponsiveOptionsManager,\n ResponsiveOptionObject,\n} from '../Base/managers/ResponsiveOptionsManager.js';\nimport { isDefined, isObject } from '../utils/index.js';\n\n/**\n * Extends the configuration of an existing class.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withResponsiveOptions.html\n */\nexport function withResponsiveOptions<S extends Base>(\n BaseClass: typeof Base,\n { responsiveOptions = [] } = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithResponsiveOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Configure responsive options.\n */\n get __config() {\n const config = super.__config;\n const options = config.options;\n\n for (const option of responsiveOptions) {\n if (isDefined(options[option])) {\n const oldOption = options[option];\n options[option] = {\n type: isObject(oldOption)\n ? (oldOption as OptionObject).type\n : (oldOption as OptionType),\n responsive: true,\n } as ResponsiveOptionObject;\n }\n }\n\n return config;\n }\n\n /**\n * Get managers.\n */\n get __managers(): Managers & { OptionsManager: typeof ResponsiveOptionsManager } {\n return {\n ...super.__managers,\n OptionsManager: ResponsiveOptionsManager,\n };\n }\n }\n\n // @ts-ignore\n return WithResponsiveOptions;\n}\n"],
|
|
5
5
|
"mappings": "AAGA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,WAAW,gBAAgB;AAM7B,SAAS,sBACd,WACA,EAAE,oBAAoB,CAAC,EAAE,IAAI,CAAC,GACG;AAAA,EAIjC,MAAM,8BAA+D,UAAa;AAAA;AAAA;AAAA;AAAA,IAIhF,IAAI,WAAW;AACb,YAAM,SAAS,MAAM;AACrB,YAAM,UAAU,OAAO;AAEvB,iBAAW,UAAU,mBAAmB;AACtC,YAAI,UAAU,QAAQ,MAAM,CAAC,GAAG;AAC9B,gBAAM,YAAY,QAAQ,MAAM;AAChC,kBAAQ,MAAM,IAAI;AAAA,YAChB,MAAM,SAAS,SAAS,IACnB,UAA2B,OAC3B;AAAA,YACL,YAAY;AAAA,UACd;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,aAA6E;AAC/E,aAAO;AAAA,QACL,GAAG,MAAM;AAAA,QACT,gBAAgB;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -53,5 +53,5 @@ export interface WithScrolledInViewInterface extends BaseInterface {
|
|
|
53
53
|
/**
|
|
54
54
|
* Add scrolled in view capabilities to a component.
|
|
55
55
|
* @link https://js-toolkit.studiometa.dev/api/decorators/withScrolledInView.html
|
|
56
|
-
*/
|
|
56
|
+
*/
|
|
57
57
|
export declare function withScrolledInView<S extends Base = Base>(BaseClass: typeof Base, options?: WithScrolledInViewOptions): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { useScroll } from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n domScheduler as scheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\nfunction updateProgress(\n props: ScrollInViewProps,\n axis: 'x' | 'y',\n progressKey: 'progress' | 'dampedProgress',\n currentKey: 'current' | 'dampedCurrent',\n) {\n props[progressKey][axis] =\n props.start[axis] === props.end[axis]\n ? 0\n : clamp01(\n (props[currentKey][axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(useScroll().props()[axis], props.start[axis], props.end[axis]);\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n updateProgress(props, axis, 'progress', 'current');\n updateProgress(props, axis, 'dampedProgress', 'dampedCurrent');\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withScrolledInView.html\n*/\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.scrollY;\n targetSizes.x += window.scrollX;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.scrollY, yStart, yEnd);\n const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.scrollX, xStart, xEnd);\n const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.read(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.write(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event: CustomEvent) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props: ScrollServiceProps) => {\n if (props.changed.y || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n mounted: () => render(),\n ticked: () => {\n const { dampFactor, dampPrecision } = this.$options;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('mounted', delegate);\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('mounted', delegate);\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { useScroll } from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n domScheduler as scheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\nfunction updateProgress(\n props: ScrollInViewProps,\n axis: 'x' | 'y',\n progressKey: 'progress' | 'dampedProgress',\n currentKey: 'current' | 'dampedCurrent',\n) {\n props[progressKey][axis] =\n props.start[axis] === props.end[axis]\n ? 0\n : clamp01(\n (props[currentKey][axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(useScroll().props()[axis], props.start[axis], props.end[axis]);\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n updateProgress(props, axis, 'progress', 'current');\n updateProgress(props, axis, 'dampedProgress', 'dampedCurrent');\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withScrolledInView.html\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.scrollY;\n targetSizes.x += window.scrollX;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.scrollY, yStart, yEnd);\n const yProgress = yStart === yEnd ? 0 : clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.scrollX, xStart, xEnd);\n const xProgress = xStart === xEnd ? 0 : clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.read(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.write(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event: CustomEvent) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props: ScrollServiceProps) => {\n if (props.changed.y || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n mounted: () => render(),\n ticked: () => {\n const { dampFactor, dampPrecision } = this.$options;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('mounted', delegate);\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('mounted', delegate);\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
5
|
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/createApp.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export type CreateAppOptions = Partial<Features> & {
|
|
|
7
7
|
* Instantiate and mount the given component on the given root element when the page has been loaded
|
|
8
8
|
* and return a function to use the app instance when it is ready.
|
|
9
9
|
* @link https://js-toolkit.studiometa.dev/api/helpers/createApp.html
|
|
10
|
-
*/
|
|
10
|
+
*/
|
|
11
11
|
export declare function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(App: S, options?: HTMLElement | CreateAppOptions): () => Promise<S & Base<T>>;
|
package/helpers/createApp.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { features } from "../Base/features.js";
|
|
2
2
|
import { defineFeatures } from "./defineFeatures.js";
|
|
3
|
+
import { isDev } from "../utils/index.js";
|
|
4
|
+
import { logTree } from "./logTree.js";
|
|
3
5
|
function createApp(App, options = {}) {
|
|
4
6
|
let app;
|
|
5
|
-
const {
|
|
6
|
-
root = document.body,
|
|
7
|
-
...featureOptions
|
|
8
|
-
} = options instanceof HTMLElement ? { root: options } : options;
|
|
7
|
+
const { root = document.body, ...featureOptions } = options instanceof HTMLElement ? { root: options } : options;
|
|
9
8
|
defineFeatures(featureOptions);
|
|
10
9
|
async function init() {
|
|
11
10
|
app = new App(root);
|
|
12
11
|
await app.$mount();
|
|
12
|
+
if (isDev) {
|
|
13
|
+
globalThis.$logTree = () => logTree(app);
|
|
14
|
+
}
|
|
13
15
|
return app;
|
|
14
16
|
}
|
|
15
17
|
let p;
|
package/helpers/createApp.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { defineFeatures } from './defineFeatures.js';\n\nexport type CreateAppOptions = Partial<Features> & {\n root?: HTMLElement;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n * @link https://js-toolkit.studiometa.dev/api/helpers/createApp.html\n*/\nexport function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n options: HTMLElement | CreateAppOptions = {},\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const {
|
|
5
|
-
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { defineFeatures } from './defineFeatures.js';\nimport { isDev } from '../utils/index.js';\nimport { logTree } from './logTree.js';\n\nexport type CreateAppOptions = Partial<Features> & {\n root?: HTMLElement;\n};\n\n/**\n * Instantiate and mount the given component on the given root element when the page has been loaded\n * and return a function to use the app instance when it is ready.\n * @link https://js-toolkit.studiometa.dev/api/helpers/createApp.html\n */\nexport function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n options: HTMLElement | CreateAppOptions = {},\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const { root = document.body, ...featureOptions } =\n options instanceof HTMLElement ? { root: options } : options;\n\n defineFeatures(featureOptions);\n\n async function init() {\n app = new App(root) as S & Base<T>;\n await app.$mount();\n if (isDev) {\n globalThis.$logTree = () => logTree(app);\n }\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('blocking')) {\n p = init();\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AACtB,SAAS,eAAe;AAWjB,SAAS,UACd,KACA,UAA0C,CAAC,GACf;AAC5B,MAAI;AACJ,QAAM,EAAE,OAAO,SAAS,MAAM,GAAG,eAAe,IAC9C,mBAAmB,cAAc,EAAE,MAAM,QAAQ,IAAI;AAEvD,iBAAe,cAAc;AAE7B,iBAAe,OAAO;AACpB,UAAM,IAAI,IAAI,IAAI;AAClB,UAAM,IAAI,OAAO;AACjB,QAAI,OAAO;AACT,iBAAW,WAAW,MAAM,QAAQ,GAAG;AAAA,IACzC;AACA,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,QAAI,KAAK;AAAA,EACX,OAAO;AACL,QAAI,IAAI,QAAqB,CAAC,YAAY;AACxC,UAAI,SAAS,eAAe,YAAY;AACtC,gBAAQ,KAAK,CAAC;AAAA,MAChB,OAAO;AACL,iBAAS,iBAAiB,oBAAoB,MAAM;AAClD,cAAI,SAAS,eAAe,YAAY;AACtC,oBAAQ,KAAK,CAAC;AAAA,UAChB;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,5 +2,5 @@ import type { Base, BaseConstructor } from '../Base/index.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Get the closest parent of a component.
|
|
4
4
|
* @link https://js-toolkit.studiometa.dev/api/helpers/getClosestParent.html
|
|
5
|
-
*/
|
|
5
|
+
*/
|
|
6
6
|
export declare function getClosestParent<T extends BaseConstructor>(childInstance: Base, ParentConstructor: T): InstanceType<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getClosestParent.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getInstanceFromElement } from './getInstanceFromElement.js';\nimport { getAncestorWhere } from '../utils/index.js';\n\n/**\n * Get the closest parent of a component.\n * @link https://js-toolkit.studiometa.dev/api/helpers/getClosestParent.html\n*/\nexport function getClosestParent<T extends BaseConstructor>(\n childInstance: Base,\n ParentConstructor: T,\n) {\n const parentEl = getAncestorWhere(\n childInstance.$el,\n (element) => element && getInstanceFromElement(element, ParentConstructor) !== null,\n );\n\n return parentEl ? getInstanceFromElement(parentEl, ParentConstructor) : null;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getInstanceFromElement } from './getInstanceFromElement.js';\nimport { getAncestorWhere } from '../utils/index.js';\n\n/**\n * Get the closest parent of a component.\n * @link https://js-toolkit.studiometa.dev/api/helpers/getClosestParent.html\n */\nexport function getClosestParent<T extends BaseConstructor>(\n childInstance: Base,\n ParentConstructor: T,\n) {\n const parentEl = getAncestorWhere(\n childInstance.$el,\n (element) => element && getInstanceFromElement(element, ParentConstructor) !== null,\n );\n\n return parentEl ? getInstanceFromElement(parentEl, ParentConstructor) : null;\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,wBAAwB;AAM1B,SAAS,iBACd,eACA,mBACA;AACA,QAAM,WAAW;AAAA,IACf,cAAc;AAAA,IACd,CAAC,YAAY,WAAW,uBAAuB,SAAS,iBAAiB,MAAM;AAAA,EACjF;AAEA,SAAO,WAAW,uBAAuB,UAAU,iBAAiB,IAAI;AAC1E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,7 +8,7 @@ import { Base } from '../Base/index.js';
|
|
|
8
8
|
* @param {string} childrenName
|
|
9
9
|
* @return {T[]}
|
|
10
10
|
* @link https://js-toolkit.studiometa.dev/api/helpers/getDirectChildren.html
|
|
11
|
-
*/
|
|
11
|
+
*/
|
|
12
12
|
export declare function getDirectChildren<T extends Base = Base>(parentInstance: Base, parentName: string, childrenName: string): T[];
|
|
13
13
|
/**
|
|
14
14
|
* Test if a component instance is a direct child from the given component.
|
|
@@ -19,5 +19,5 @@ export declare function getDirectChildren<T extends Base = Base>(parentInstance:
|
|
|
19
19
|
* @param {Base} childInstance
|
|
20
20
|
* @return {boolean}
|
|
21
21
|
* @link https://js-toolkit.studiometa.dev/api/helpers/isDirectChild.html
|
|
22
|
-
*/
|
|
22
|
+
*/
|
|
23
23
|
export declare function isDirectChild(parentInstance: any, parentName: any, childrenName: any, childInstance: any): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getDirectChildren.ts"],
|
|
4
|
-
"sourcesContent": ["import { Base, BaseProps } from '../Base/index.js';\nimport { isArray } from '../utils/index.js';\n\n/**\n * Get direct children from a parent when working with nested components.\n *\n * @template {Base} T\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @return {T[]}\n * @link https://js-toolkit.studiometa.dev/api/helpers/getDirectChildren.html\n*/\nexport function getDirectChildren<T extends Base = Base>(\n parentInstance: Base,\n parentName: string,\n childrenName: string,\n): T[] {\n const allChildren = parentInstance.__children.props;\n const children = allChildren[childrenName] as Base<BaseProps>[];\n const nestedParents = allChildren[parentName] as Base<BaseProps>[];\n\n if (!isArray(children)) {\n return [];\n }\n\n if (!isArray(nestedParents) || nestedParents.length <= 0) {\n return children as T[];\n }\n\n const directChildren = [];\n\n for (const child of children) {\n for (const nestedParent of nestedParents) {\n const nestedChildren = nestedParent.__children.props[childrenName] as Base<BaseProps>[];\n\n if (isArray(nestedChildren) && nestedChildren.includes(child)) {\n continue;\n }\n\n directChildren.push(child);\n }\n }\n\n return directChildren;\n}\n\n/**\n * Test if a component instance is a direct child from the given component.\n *\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @param {Base} childInstance\n * @return {boolean}\n * @link https://js-toolkit.studiometa.dev/api/helpers/isDirectChild.html\n*/\nexport function isDirectChild(parentInstance, parentName, childrenName, childInstance) {\n return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);\n}\n"],
|
|
4
|
+
"sourcesContent": ["import { Base, BaseProps } from '../Base/index.js';\nimport { isArray } from '../utils/index.js';\n\n/**\n * Get direct children from a parent when working with nested components.\n *\n * @template {Base} T\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @return {T[]}\n * @link https://js-toolkit.studiometa.dev/api/helpers/getDirectChildren.html\n */\nexport function getDirectChildren<T extends Base = Base>(\n parentInstance: Base,\n parentName: string,\n childrenName: string,\n): T[] {\n const allChildren = parentInstance.__children.props;\n const children = allChildren[childrenName] as Base<BaseProps>[];\n const nestedParents = allChildren[parentName] as Base<BaseProps>[];\n\n if (!isArray(children)) {\n return [];\n }\n\n if (!isArray(nestedParents) || nestedParents.length <= 0) {\n return children as T[];\n }\n\n const directChildren = [];\n\n for (const child of children) {\n for (const nestedParent of nestedParents) {\n const nestedChildren = nestedParent.__children.props[childrenName] as Base<BaseProps>[];\n\n if (isArray(nestedChildren) && nestedChildren.includes(child)) {\n continue;\n }\n\n directChildren.push(child);\n }\n }\n\n return directChildren;\n}\n\n/**\n * Test if a component instance is a direct child from the given component.\n *\n * @param {Base} parentInstance\n * @param {string} parentName\n * @param {string} childrenName\n * @param {Base} childInstance\n * @return {boolean}\n * @link https://js-toolkit.studiometa.dev/api/helpers/isDirectChild.html\n */\nexport function isDirectChild(parentInstance, parentName, childrenName, childInstance) {\n return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,eAAe;AAYjB,SAAS,kBACd,gBACA,YACA,cACK;AACL,QAAM,cAAc,eAAe,WAAW;AAC9C,QAAM,WAAW,YAAY,YAAY;AACzC,QAAM,gBAAgB,YAAY,UAAU;AAE5C,MAAI,CAAC,QAAQ,QAAQ,GAAG;AACtB,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,CAAC,QAAQ,aAAa,KAAK,cAAc,UAAU,GAAG;AACxD,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB,CAAC;AAExB,aAAW,SAAS,UAAU;AAC5B,eAAW,gBAAgB,eAAe;AACxC,YAAM,iBAAiB,aAAa,WAAW,MAAM,YAAY;AAEjE,UAAI,QAAQ,cAAc,KAAK,eAAe,SAAS,KAAK,GAAG;AAC7D;AAAA,MACF;AAEA,qBAAe,KAAK,KAAK;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO;AACT;AAYO,SAAS,cAAc,gBAAgB,YAAY,cAAc,eAAe;AACrF,SAAO,kBAAkB,gBAAgB,YAAY,YAAY,EAAE,SAAS,aAAa;AAC3F;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,5 +2,5 @@ import type { BaseConstructor, BaseEl } from '../Base/index.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Get a component instance from a DOM element.
|
|
4
4
|
* @link https://js-toolkit.studiometa.dev/api/helpers/getInstanceFromElement.html
|
|
5
|
-
*/
|
|
5
|
+
*/
|
|
6
6
|
export declare function getInstanceFromElement<T extends BaseConstructor>(element: BaseEl, Constructor: T): InstanceType<T> | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/getInstanceFromElement.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n * @link https://js-toolkit.studiometa.dev/api/helpers/getInstanceFromElement.html\n*/\nexport function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element || !element.__base__ || !element.__base__.has(Constructor.config.name)) {\n return null;\n }\n\n return element.__base__.get(Constructor.config.name) as InstanceType<T>;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor, BaseEl } from '../Base/index.js';\n\n/**\n * Get a component instance from a DOM element.\n * @link https://js-toolkit.studiometa.dev/api/helpers/getInstanceFromElement.html\n */\nexport function getInstanceFromElement<T extends BaseConstructor>(\n element: BaseEl,\n Constructor: T,\n): InstanceType<T> | null {\n if (!element || !element.__base__ || !element.__base__.has(Constructor.config.name)) {\n return null;\n }\n\n return element.__base__.get(Constructor.config.name) as InstanceType<T>;\n}\n"],
|
|
5
5
|
"mappings": "AAMO,SAAS,uBACd,SACA,aACwB;AACxB,MAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,CAAC,QAAQ,SAAS,IAAI,YAAY,OAAO,IAAI,GAAG;AACnF,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,SAAS,IAAI,YAAY,OAAO,IAAI;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ import type { Base, BaseConstructor } from '../Base/index.js';
|
|
|
13
13
|
* The parent component.
|
|
14
14
|
* @return {Promise<InstanceType<T>>}
|
|
15
15
|
* @link https://js-toolkit.studiometa.dev/api/helpers/importOnInteraction.html
|
|
16
|
-
*/
|
|
16
|
+
*/
|
|
17
17
|
export declare function importOnInteraction<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
18
18
|
default: T;
|
|
19
19
|
}>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], events: string | string[], parent?: Base): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importOnInteraction.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { isString, getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component on an interaction.\n *\n * @template {BaseConstructor} [T=BaseConstructor]\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {string|string[]} events\n * The events to listen to to trigger the import.\n * @param {Base} [parent]\n * The parent component.\n * @return {Promise<InstanceType<T>>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importOnInteraction.html\n*/\nexport function importOnInteraction<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n events: string | string[],\n parent?: Base,\n): Promise<T> {\n const normalizedEvents = isString(events) ? [events] : events;\n\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n const eventListenerOptions = {\n capture: true,\n passive: true,\n once: true,\n };\n const handler = () => {\n resolver(resolve);\n };\n\n for (const element of elements) {\n for (const event of normalizedEvents) {\n element.addEventListener(event, handler, eventListenerOptions);\n }\n }\n });\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { isString, getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component on an interaction.\n *\n * @template {BaseConstructor} [T=BaseConstructor]\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {string|string[]} events\n * The events to listen to to trigger the import.\n * @param {Base} [parent]\n * The parent component.\n * @return {Promise<InstanceType<T>>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importOnInteraction.html\n */\nexport function importOnInteraction<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n events: string | string[],\n parent?: Base,\n): Promise<T> {\n const normalizedEvents = isString(events) ? [events] : events;\n\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n const eventListenerOptions = {\n capture: true,\n passive: true,\n once: true,\n };\n const handler = () => {\n resolver(resolve);\n };\n\n for (const element of elements) {\n for (const event of normalizedEvents) {\n element.addEventListener(event, handler, eventListenerOptions);\n }\n }\n });\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,UAAU,4BAA4B;AAiBxC,SAAS,oBACd,IACA,yBACA,QACA,QACY;AACZ,QAAM,mBAAmB,SAAS,MAAM,IAAI,CAAC,MAAM,IAAI;AAEvD,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,kBAAkB,yBAAyB,QAAQ,GAAG;AACvE,UAAM,uBAAuB;AAAA,MAC3B,SAAS;AAAA,MACT,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AACA,UAAM,UAAU,MAAM;AACpB,eAAS,OAAO;AAAA,IAClB;AAEA,eAAW,WAAW,UAAU;AAC9B,iBAAW,SAAS,kBAAkB;AACpC,gBAAQ,iBAAiB,OAAO,SAAS,oBAAoB;AAAA,MAC/D;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ import type { BaseConstructor } from '../Base/index.js';
|
|
|
9
9
|
* The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)
|
|
10
10
|
* @return {Promise<T>}
|
|
11
11
|
* @link https://js-toolkit.studiometa.dev/api/helpers/importOnMediaQuery.html
|
|
12
|
-
*/
|
|
12
|
+
*/
|
|
13
13
|
export declare function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
14
14
|
default: T;
|
|
15
15
|
}>, media: string): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importOnMediaQuery.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when given media query is true.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string} media\n * The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importOnMediaQuery.html\n*/\nexport function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n media: string,\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const mediaQueryList = window.matchMedia(media);\n\n if (mediaQueryList.matches) {\n resolver(resolve);\n }\n\n const changeHandler = (event: MediaQueryListEvent) => {\n if (event.matches) {\n setTimeout(() => {\n // Remove listener and mount the component\n resolver(resolve, () => mediaQueryList.removeEventListener('change', changeHandler));\n }, 0);\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n });\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when given media query is true.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string} media\n * The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importOnMediaQuery.html\n */\nexport function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n media: string,\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const mediaQueryList = window.matchMedia(media);\n\n if (mediaQueryList.matches) {\n resolver(resolve);\n }\n\n const changeHandler = (event: MediaQueryListEvent) => {\n if (event.matches) {\n setTimeout(() => {\n // Remove listener and mount the component\n resolver(resolve, () => mediaQueryList.removeEventListener('change', changeHandler));\n }, 0);\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n });\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,4BAA4B;AAa9B,SAAS,mBACd,IACA,OACY;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,iBAAiB,OAAO,WAAW,KAAK;AAE9C,QAAI,eAAe,SAAS;AAC1B,eAAS,OAAO;AAAA,IAClB;AAEA,UAAM,gBAAgB,CAAC,UAA+B;AACpD,UAAI,MAAM,SAAS;AACjB,mBAAW,MAAM;AAEf,mBAAS,SAAS,MAAM,eAAe,oBAAoB,UAAU,aAAa,CAAC;AAAA,QACrF,GAAG,CAAC;AAAA,MACN;AAAA,IACF;AAGA,mBAAe,iBAAiB,UAAU,aAAa;AAAA,EACzD,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,7 @@ type ImportWhenIdleOptions = {
|
|
|
12
12
|
* The time to wait before triggering the callback if never idle.
|
|
13
13
|
* @return {Promise<T>}
|
|
14
14
|
* @link https://js-toolkit.studiometa.dev/api/helpers/importWhenIdle.html
|
|
15
|
-
*/
|
|
15
|
+
*/
|
|
16
16
|
export declare function importWhenIdle<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
17
17
|
default: T;
|
|
18
18
|
}>, { timeout }?: ImportWhenIdleOptions): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenIdle.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils/index.js';\n\ntype ImportWhenIdleOptions = {\n timeout?: number;\n};\n\n/**\n * Import a component when user is idle.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {ImportWhenIdleOptions} [options]\n * The time to wait before triggering the callback if never idle.\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importWhenIdle.html\n*/\nexport function importWhenIdle<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n { timeout = 1 }: ImportWhenIdleOptions = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n if (!('requestIdleCallback' in window)) {\n setTimeout(() => {\n resolver(resolve);\n }, timeout);\n } else {\n window.requestIdleCallback(\n () => {\n setTimeout(() => {\n resolver(resolve);\n }, 0);\n },\n { timeout },\n );\n }\n });\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { getComponentResolver } from '../utils/index.js';\n\ntype ImportWhenIdleOptions = {\n timeout?: number;\n};\n\n/**\n * Import a component when user is idle.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {ImportWhenIdleOptions} [options]\n * The time to wait before triggering the callback if never idle.\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importWhenIdle.html\n */\nexport function importWhenIdle<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n { timeout = 1 }: ImportWhenIdleOptions = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n if (!('requestIdleCallback' in window)) {\n setTimeout(() => {\n resolver(resolve);\n }, timeout);\n } else {\n window.requestIdleCallback(\n () => {\n setTimeout(() => {\n resolver(resolve);\n }, 0);\n },\n { timeout },\n );\n }\n });\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,4BAA4B;AAiB9B,SAAS,eACd,IACA,EAAE,UAAU,EAAE,IAA2B,CAAC,GAC9B;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAI,EAAE,yBAAyB,SAAS;AACtC,iBAAW,MAAM;AACf,iBAAS,OAAO;AAAA,MAClB,GAAG,OAAO;AAAA,IACZ,OAAO;AACL,aAAO;AAAA,QACL,MAAM;AACJ,qBAAW,MAAM;AACf,qBAAS,OAAO;AAAA,UAClB,GAAG,CAAC;AAAA,QACN;AAAA,QACA,EAAE,QAAQ;AAAA,MACZ;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,7 @@ import type { BaseConstructor } from '../Base/index.js';
|
|
|
6
6
|
* @param {() => Promise<T|{default:T}>} fn
|
|
7
7
|
* @return {Promise<T>}
|
|
8
8
|
* @link https://js-toolkit.studiometa.dev/api/helpers/importWhenPrefersMotion.html
|
|
9
|
-
*/
|
|
9
|
+
*/
|
|
10
10
|
export declare function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
11
11
|
default: T;
|
|
12
12
|
}>): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenPrefersMotion.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { importOnMediaQuery } from './importOnMediaQuery.js';\n\n/**\n * Import a component if user does not reduce motion.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importWhenPrefersMotion.html\n*/\nexport function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n): Promise<T> {\n return importOnMediaQuery(fn, 'not (prefers-reduced-motion)');\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConstructor } from '../Base/index.js';\nimport { importOnMediaQuery } from './importOnMediaQuery.js';\n\n/**\n * Import a component if user does not reduce motion.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importWhenPrefersMotion.html\n */\nexport function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n): Promise<T> {\n return importOnMediaQuery(fn, 'not (prefers-reduced-motion)');\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,0BAA0B;AAU5B,SAAS,wBACd,IACY;AACZ,SAAO,mBAAmB,IAAI,8BAA8B;AAC9D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ import type { Base, BaseConstructor } from '../Base/index.js';
|
|
|
13
13
|
* Options for the `IntersectionObserver` instance.
|
|
14
14
|
* @return {Promise<T>}
|
|
15
15
|
* @link https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html
|
|
16
|
-
*/
|
|
16
|
+
*/
|
|
17
17
|
export declare function importWhenVisible<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
18
18
|
default: T;
|
|
19
19
|
}>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], parent?: Base, observerOptions?: IntersectionObserverInit): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/importWhenVisible.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when it is visible.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {Base} [parent]\n * The parent component.\n * @param {IntersectionObserverInit} [observerOptions]\n * Options for the `IntersectionObserver` instance.\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html\n*/\nexport function importWhenVisible<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n parent?: Base,\n observerOptions: IntersectionObserverInit = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const observer = new IntersectionObserver((entries) => {\n const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);\n if (someEntriesAreVisible) {\n setTimeout(() => {\n resolver(resolve, () => observer.disconnect());\n }, 0);\n }\n }, observerOptions);\n\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n for (const element of elements) observer.observe(element);\n });\n}\n"],
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor } from '../Base/index.js';\nimport { getTargetElements } from './utils.js';\nimport { getComponentResolver } from '../utils/index.js';\n\n/**\n * Import a component when it is visible.\n *\n * @template {BaseConstructor} T\n * @param {() => Promise<T|{default:T}>} fn\n * The import function.\n * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement\n * The name or selector for the component.\n * @param {Base} [parent]\n * The parent component.\n * @param {IntersectionObserverInit} [observerOptions]\n * Options for the `IntersectionObserver` instance.\n * @return {Promise<T>}\n * @link https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html\n */\nexport function importWhenVisible<T extends BaseConstructor = BaseConstructor>(\n fn: () => Promise<T | { default: T }>,\n nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],\n parent?: Base,\n observerOptions: IntersectionObserverInit = {},\n): Promise<T> {\n const resolver = getComponentResolver(fn);\n\n return new Promise((resolve) => {\n const observer = new IntersectionObserver((entries) => {\n const someEntriesAreVisible = entries.some((entry) => entry.isIntersecting);\n if (someEntriesAreVisible) {\n setTimeout(() => {\n resolver(resolve, () => observer.disconnect());\n }, 0);\n }\n }, observerOptions);\n\n const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);\n for (const element of elements) observer.observe(element);\n });\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAiB9B,SAAS,kBACd,IACA,yBACA,QACA,kBAA4C,CAAC,GACjC;AACZ,QAAM,WAAW,qBAAqB,EAAE;AAExC,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,WAAW,IAAI,qBAAqB,CAAC,YAAY;AACrD,YAAM,wBAAwB,QAAQ,KAAK,CAAC,UAAU,MAAM,cAAc;AAC1E,UAAI,uBAAuB;AACzB,mBAAW,MAAM;AACf,mBAAS,SAAS,MAAM,SAAS,WAAW,CAAC;AAAA,QAC/C,GAAG,CAAC;AAAA,MACN;AAAA,IACF,GAAG,eAAe;AAElB,UAAM,WAAW,kBAAkB,yBAAyB,QAAQ,GAAG;AACvE,eAAW,WAAW,SAAU,UAAS,QAAQ,OAAO;AAAA,EAC1D,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from './importOnMediaQuery.js';
|
|
|
8
8
|
export * from './importWhenIdle.js';
|
|
9
9
|
export * from './importWhenPrefersMotion.js';
|
|
10
10
|
export * from './importWhenVisible.js';
|
|
11
|
+
export * from './logTree.js';
|
|
11
12
|
export * from './registerComponent.js';
|
|
12
13
|
export { type QueryOptions, queryComponent, queryComponentAll, closestComponent, } from './queryComponent.js';
|
package/helpers/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./importOnMediaQuery.js";
|
|
|
8
8
|
export * from "./importWhenIdle.js";
|
|
9
9
|
export * from "./importWhenPrefersMotion.js";
|
|
10
10
|
export * from "./importWhenVisible.js";
|
|
11
|
+
export * from "./logTree.js";
|
|
11
12
|
export * from "./registerComponent.js";
|
|
12
13
|
import {
|
|
13
14
|
queryComponent,
|
package/helpers/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './createApp.js';\nexport * from './defineFeatures.js';\nexport * from './getClosestParent.js';\nexport * from './getDirectChildren.js';\nexport * from './getInstanceFromElement.js';\nexport * from './importOnInteraction.js';\nexport * from './importOnMediaQuery.js';\nexport * from './importWhenIdle.js';\nexport * from './importWhenPrefersMotion.js';\nexport * from './importWhenVisible.js';\nexport * from './registerComponent.js';\nexport {\n type QueryOptions,\n queryComponent,\n queryComponentAll,\n closestComponent,\n} from './queryComponent.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
4
|
+
"sourcesContent": ["export * from './createApp.js';\nexport * from './defineFeatures.js';\nexport * from './getClosestParent.js';\nexport * from './getDirectChildren.js';\nexport * from './getInstanceFromElement.js';\nexport * from './importOnInteraction.js';\nexport * from './importOnMediaQuery.js';\nexport * from './importWhenIdle.js';\nexport * from './importWhenPrefersMotion.js';\nexport * from './importWhenVisible.js';\nexport * from './logTree.js';\nexport * from './registerComponent.js';\nexport {\n type QueryOptions,\n queryComponent,\n queryComponentAll,\n closestComponent,\n} from './queryComponent.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Base } from '../Base/Base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Log the component tree starting from the given instance.
|
|
4
|
+
*
|
|
5
|
+
* Uses the global instance registry and DOM containment to build the tree,
|
|
6
|
+
* without relying on the deprecated `$children` API.
|
|
7
|
+
*
|
|
8
|
+
* @param {Base} instance The root component instance.
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* import { createApp, logTree } from '@studiometa/js-toolkit';
|
|
12
|
+
*
|
|
13
|
+
* const useApp = createApp(App);
|
|
14
|
+
* useApp().then((app) => logTree(app));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function logTree(instance: Base): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getInstances } from "../Base/index.js";
|
|
2
|
+
function buildTree(root) {
|
|
3
|
+
const allInstances = getInstances();
|
|
4
|
+
const rootNode = { instance: root, children: [] };
|
|
5
|
+
const descendants = [];
|
|
6
|
+
for (const instance of allInstances) {
|
|
7
|
+
if (instance !== root && root.$el.contains(instance.$el)) {
|
|
8
|
+
descendants.push(instance);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
descendants.sort((a, b) => {
|
|
12
|
+
const position = a.$el.compareDocumentPosition(b.$el);
|
|
13
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
14
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
|
15
|
+
return 0;
|
|
16
|
+
});
|
|
17
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
18
|
+
nodeMap.set(root, rootNode);
|
|
19
|
+
for (const instance of descendants) {
|
|
20
|
+
const node = { instance, children: [] };
|
|
21
|
+
nodeMap.set(instance, node);
|
|
22
|
+
let parentNode = rootNode;
|
|
23
|
+
for (const [candidate, candidateNode] of nodeMap) {
|
|
24
|
+
if (candidate !== instance && candidate.$el.contains(instance.$el) && // Pick the most specific (deepest) container
|
|
25
|
+
parentNode.instance.$el.contains(candidate.$el)) {
|
|
26
|
+
parentNode = candidateNode;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
parentNode.children.push(node);
|
|
30
|
+
}
|
|
31
|
+
return rootNode;
|
|
32
|
+
}
|
|
33
|
+
function logNode(node) {
|
|
34
|
+
const { instance } = node;
|
|
35
|
+
const mounted = instance.$isMounted;
|
|
36
|
+
const status = mounted ? "\u25CF" : "\u25CB";
|
|
37
|
+
const label = `${status} ${instance.$id}`;
|
|
38
|
+
if (node.children.length > 0) {
|
|
39
|
+
console.groupCollapsed(label, instance.$el);
|
|
40
|
+
for (const child of node.children) {
|
|
41
|
+
logNode(child);
|
|
42
|
+
}
|
|
43
|
+
console.groupEnd();
|
|
44
|
+
} else {
|
|
45
|
+
console.log(label, instance.$el);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function logTree(instance) {
|
|
49
|
+
const tree = buildTree(instance);
|
|
50
|
+
console.group(`\u{1F333} ${instance.$config.name}`);
|
|
51
|
+
for (const child of tree.children) {
|
|
52
|
+
logNode(child);
|
|
53
|
+
}
|
|
54
|
+
console.groupEnd();
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
logTree
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=logTree.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/helpers/logTree.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Base } from '../Base/Base.js';\nimport { getInstances } from '../Base/index.js';\n\n/**\n * Build a tree structure from a flat set of instances using DOM containment.\n */\nfunction buildTree(root: Base): TreeNode {\n const allInstances = getInstances();\n const rootNode: TreeNode = { instance: root, children: [] };\n\n // Collect all instances that are descendants of root (excluding root itself)\n const descendants: Base[] = [];\n for (const instance of allInstances) {\n if (instance !== root && root.$el.contains(instance.$el)) {\n descendants.push(instance);\n }\n }\n\n // Sort by DOM order (depth-first)\n descendants.sort((a, b) => {\n const position = a.$el.compareDocumentPosition(b.$el);\n if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1;\n return 0;\n });\n\n // Build tree: assign each instance to its closest ancestor in the tree\n const nodeMap = new Map<Base, TreeNode>();\n nodeMap.set(root, rootNode);\n\n for (const instance of descendants) {\n const node: TreeNode = { instance, children: [] };\n nodeMap.set(instance, node);\n\n // Find the closest ancestor that is already in the tree\n let parentNode = rootNode;\n for (const [candidate, candidateNode] of nodeMap) {\n if (\n candidate !== instance &&\n candidate.$el.contains(instance.$el) &&\n // Pick the most specific (deepest) container\n parentNode.instance.$el.contains(candidate.$el)\n ) {\n parentNode = candidateNode;\n }\n }\n\n parentNode.children.push(node);\n }\n\n return rootNode;\n}\n\ninterface TreeNode {\n instance: Base;\n children: TreeNode[];\n}\n\n/**\n * Log a tree node and its children using console groups.\n */\nfunction logNode(node: TreeNode): void {\n const { instance } = node;\n const mounted = instance.$isMounted;\n const status = mounted ? '\u25CF' : '\u25CB';\n const label = `${status} ${instance.$id}`;\n\n if (node.children.length > 0) {\n console.groupCollapsed(label, instance.$el);\n for (const child of node.children) {\n logNode(child);\n }\n console.groupEnd();\n } else {\n console.log(label, instance.$el);\n }\n}\n\n/**\n * Log the component tree starting from the given instance.\n *\n * Uses the global instance registry and DOM containment to build the tree,\n * without relying on the deprecated `$children` API.\n *\n * @param {Base} instance The root component instance.\n * @example\n * ```js\n * import { createApp, logTree } from '@studiometa/js-toolkit';\n *\n * const useApp = createApp(App);\n * useApp().then((app) => logTree(app));\n * ```\n */\nexport function logTree(instance: Base): void {\n const tree = buildTree(instance);\n console.group(`\uD83C\uDF33 ${instance.$config.name}`);\n for (const child of tree.children) {\n logNode(child);\n }\n console.groupEnd();\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAK7B,SAAS,UAAU,MAAsB;AACvC,QAAM,eAAe,aAAa;AAClC,QAAM,WAAqB,EAAE,UAAU,MAAM,UAAU,CAAC,EAAE;AAG1D,QAAM,cAAsB,CAAC;AAC7B,aAAW,YAAY,cAAc;AACnC,QAAI,aAAa,QAAQ,KAAK,IAAI,SAAS,SAAS,GAAG,GAAG;AACxD,kBAAY,KAAK,QAAQ;AAAA,IAC3B;AAAA,EACF;AAGA,cAAY,KAAK,CAAC,GAAG,MAAM;AACzB,UAAM,WAAW,EAAE,IAAI,wBAAwB,EAAE,GAAG;AACpD,QAAI,WAAW,KAAK,4BAA6B,QAAO;AACxD,QAAI,WAAW,KAAK,4BAA6B,QAAO;AACxD,WAAO;AAAA,EACT,CAAC;AAGD,QAAM,UAAU,oBAAI,IAAoB;AACxC,UAAQ,IAAI,MAAM,QAAQ;AAE1B,aAAW,YAAY,aAAa;AAClC,UAAM,OAAiB,EAAE,UAAU,UAAU,CAAC,EAAE;AAChD,YAAQ,IAAI,UAAU,IAAI;AAG1B,QAAI,aAAa;AACjB,eAAW,CAAC,WAAW,aAAa,KAAK,SAAS;AAChD,UACE,cAAc,YACd,UAAU,IAAI,SAAS,SAAS,GAAG;AAAA,MAEnC,WAAW,SAAS,IAAI,SAAS,UAAU,GAAG,GAC9C;AACA,qBAAa;AAAA,MACf;AAAA,IACF;AAEA,eAAW,SAAS,KAAK,IAAI;AAAA,EAC/B;AAEA,SAAO;AACT;AAUA,SAAS,QAAQ,MAAsB;AACrC,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,UAAU,SAAS;AACzB,QAAM,SAAS,UAAU,WAAM;AAC/B,QAAM,QAAQ,GAAG,MAAM,IAAI,SAAS,GAAG;AAEvC,MAAI,KAAK,SAAS,SAAS,GAAG;AAC5B,YAAQ,eAAe,OAAO,SAAS,GAAG;AAC1C,eAAW,SAAS,KAAK,UAAU;AACjC,cAAQ,KAAK;AAAA,IACf;AACA,YAAQ,SAAS;AAAA,EACnB,OAAO;AACL,YAAQ,IAAI,OAAO,SAAS,GAAG;AAAA,EACjC;AACF;AAiBO,SAAS,QAAQ,UAAsB;AAC5C,QAAM,OAAO,UAAU,QAAQ;AAC/B,UAAQ,MAAM,aAAM,SAAS,QAAQ,IAAI,EAAE;AAC3C,aAAW,SAAS,KAAK,UAAU;AACjC,YAAQ,KAAK;AAAA,EACf;AACA,UAAQ,SAAS;AACnB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -42,20 +42,19 @@ function queryComponentAll(query, options = {}) {
|
|
|
42
42
|
function closestComponent(query, options = { from: null }) {
|
|
43
43
|
const { from } = options;
|
|
44
44
|
const parsedQuery = parseQuery(query);
|
|
45
|
-
|
|
46
|
-
let closestInstance = null;
|
|
45
|
+
let closestInstance;
|
|
47
46
|
getAncestorWhere(from, (element) => {
|
|
48
47
|
if (!element) return false;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const baseMap = element.__base__;
|
|
49
|
+
if (!baseMap) return false;
|
|
50
|
+
const instance = baseMap.get(parsedQuery.name);
|
|
51
|
+
if (instance && instance !== "terminated" && instanceIsMatching(instance, parsedQuery)) {
|
|
52
|
+
closestInstance = instance;
|
|
53
|
+
return true;
|
|
55
54
|
}
|
|
56
55
|
return false;
|
|
57
|
-
})
|
|
58
|
-
return closestInstance
|
|
56
|
+
});
|
|
57
|
+
return closestInstance;
|
|
59
58
|
}
|
|
60
59
|
export {
|
|
61
60
|
closestComponent,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/queryComponent.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base } from '../Base/index.js';\nimport { getInstances } from '../Base/index.js';\nimport { memo } from '../utils/memo.js';\nimport { getAncestorWhere } from '../utils/dom/ancestors.js';\n\nexport interface QueryOptions {\n from?: HTMLElement | Document;\n}\n\ntype ComponentState = 'mounted' | 'destroyed' | 'terminated';\nexport type ParsedQuery = {\n name: string;\n cssSelector?: string;\n state?: string;\n};\n\nconst REGEX_QUERY = /([a-zA-Z0-9]+)(\\((.*)\\))?(:([a-z]+))?/;\n\n/**\n * Parse a query string like 'Foo(.css-selector):mounted' into its parts.\n */\nexport const parseQuery = memo((query: string): ParsedQuery => {\n const [, name, , cssSelector, , state] = query.match(REGEX_QUERY) as [\n string,\n string,\n string | undefined,\n string | undefined,\n string | undefined,\n ComponentState | undefined,\n ];\n\n return {\n name,\n cssSelector,\n state,\n };\n});\n\nexport function instanceIsMatching(instance: Base, parsedQuery: ParsedQuery): boolean {\n if (instance.$config.name !== parsedQuery.name) return false;\n if (parsedQuery.cssSelector && !instance.$el.matches(parsedQuery.cssSelector)) return false;\n\n if (parsedQuery.state === 'mounted' && !instance.$isMounted) return false;\n if (parsedQuery.state === 'destroyed' && instance.$isMounted) return false;\n\n return true;\n}\n\n/**\n * Get the first instance of component with the given query.\n */\nexport function queryComponent<T extends Base = Base>(\n query: string,\n options: QueryOptions = {},\n): T | undefined {\n const parsedQuery = parseQuery(query);\n const { from = document } = options;\n const instances = getInstances() as
|
|
5
|
-
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,wBAAwB;AAajC,MAAM,cAAc;AAKb,MAAM,aAAa,KAAK,CAAC,UAA+B;AAC7D,QAAM,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,IAAI,MAAM,MAAM,WAAW;AAShE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF,CAAC;AAEM,SAAS,mBAAmB,UAAgB,aAAmC;AACpF,MAAI,SAAS,QAAQ,SAAS,YAAY,KAAM,QAAO;AACvD,MAAI,YAAY,eAAe,CAAC,SAAS,IAAI,QAAQ,YAAY,WAAW,EAAG,QAAO;AAEtF,MAAI,YAAY,UAAU,aAAa,CAAC,SAAS,WAAY,QAAO;AACpE,MAAI,YAAY,UAAU,eAAe,SAAS,WAAY,QAAO;AAErE,SAAO;AACT;AAKO,SAAS,eACd,OACA,UAAwB,CAAC,GACV;AACf,QAAM,cAAc,WAAW,KAAK;AACpC,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,YAAY,aAAa;AAE/B,aAAW,YAAY,WAAW;AAChC,QAAI,CAAC,mBAAmB,UAAU,WAAW,EAAG;AAChD,QAAI,SAAS,YAAY,EAAE,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,GAAG,GAAI;AAElF,WAAO;AAAA,EACT;AACF;AAKO,SAAS,kBACd,OACA,UAAwB,CAAC,GACpB;AACL,QAAM,cAAc,WAAW,KAAK;AACpC,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,YAAY,aAAa;AAC/B,QAAM,oBAAoB,oBAAI,IAAO;AAErC,aAAW,YAAY,WAAW;AAChC,QAAI,CAAC,mBAAmB,UAAU,WAAW,EAAG;AAChD,QAAI,SAAS,YAAY,EAAE,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,GAAG,GAAI;AAElF,sBAAkB,IAAI,QAAQ;AAAA,EAChC;AAEA,SAAO,MAAM,KAAK,iBAAiB;AACrC;AAKO,SAAS,iBACd,OACA,UAAiC,EAAE,MAAM,KAAK,GAC/B;AACf,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,cAAc,WAAW,KAAK;AACpC,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseEl } from '../Base/index.js';\nimport { getInstances } from '../Base/index.js';\nimport { memo } from '../utils/memo.js';\nimport { getAncestorWhere } from '../utils/dom/ancestors.js';\n\nexport interface QueryOptions {\n from?: HTMLElement | Document;\n}\n\ntype ComponentState = 'mounted' | 'destroyed' | 'terminated';\nexport type ParsedQuery = {\n name: string;\n cssSelector?: string;\n state?: string;\n};\n\nconst REGEX_QUERY = /([a-zA-Z0-9]+)(\\((.*)\\))?(:([a-z]+))?/;\n\n/**\n * Parse a query string like 'Foo(.css-selector):mounted' into its parts.\n */\nexport const parseQuery = memo((query: string): ParsedQuery => {\n const [, name, , cssSelector, , state] = query.match(REGEX_QUERY) as [\n string,\n string,\n string | undefined,\n string | undefined,\n string | undefined,\n ComponentState | undefined,\n ];\n\n return {\n name,\n cssSelector,\n state,\n };\n});\n\nexport function instanceIsMatching(instance: Base, parsedQuery: ParsedQuery): boolean {\n if (instance.$config.name !== parsedQuery.name) return false;\n if (parsedQuery.cssSelector && !instance.$el.matches(parsedQuery.cssSelector)) return false;\n\n if (parsedQuery.state === 'mounted' && !instance.$isMounted) return false;\n if (parsedQuery.state === 'destroyed' && instance.$isMounted) return false;\n\n return true;\n}\n\n/**\n * Get the first instance of component with the given query.\n */\nexport function queryComponent<T extends Base = Base>(\n query: string,\n options: QueryOptions = {},\n): T | undefined {\n const parsedQuery = parseQuery(query);\n const { from = document } = options;\n const instances = getInstances() as ReadonlySet<T>;\n\n for (const instance of instances) {\n if (!instanceIsMatching(instance, parsedQuery)) continue;\n if (from !== document && !(from === instance.$el || from.contains(instance.$el))) continue;\n\n return instance;\n }\n}\n\n/**\n * Get all instances of component with the given query.\n */\nexport function queryComponentAll<T extends Base = Base>(\n query: string,\n options: QueryOptions = {},\n): T[] {\n const parsedQuery = parseQuery(query);\n const { from = document } = options;\n const instances = getInstances() as ReadonlySet<T>;\n const selectedInstances = new Set<T>();\n\n for (const instance of instances) {\n if (!instanceIsMatching(instance, parsedQuery)) continue;\n if (from !== document && !(from === instance.$el || from.contains(instance.$el))) continue;\n\n selectedInstances.add(instance);\n }\n\n return Array.from(selectedInstances);\n}\n\n/**\n * Get the closest component instance by traversing up the DOM tree.\n */\nexport function closestComponent<T extends Base = Base>(\n query: string,\n options: { from: HTMLElement } = { from: null },\n): T | undefined {\n const { from } = options;\n const parsedQuery = parseQuery(query);\n let closestInstance: T | undefined;\n\n getAncestorWhere(from, (element) => {\n if (!element) return false;\n\n // Use the element's __base__ map for O(1) lookup by component name\n const baseMap = (element as BaseEl).__base__;\n if (!baseMap) return false;\n\n const instance = baseMap.get(parsedQuery.name) as T;\n if (\n instance &&\n instance !== ('terminated' as unknown) &&\n instanceIsMatching(instance, parsedQuery)\n ) {\n closestInstance = instance;\n return true;\n }\n\n return false;\n });\n\n return closestInstance;\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,wBAAwB;AAajC,MAAM,cAAc;AAKb,MAAM,aAAa,KAAK,CAAC,UAA+B;AAC7D,QAAM,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,IAAI,MAAM,MAAM,WAAW;AAShE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF,CAAC;AAEM,SAAS,mBAAmB,UAAgB,aAAmC;AACpF,MAAI,SAAS,QAAQ,SAAS,YAAY,KAAM,QAAO;AACvD,MAAI,YAAY,eAAe,CAAC,SAAS,IAAI,QAAQ,YAAY,WAAW,EAAG,QAAO;AAEtF,MAAI,YAAY,UAAU,aAAa,CAAC,SAAS,WAAY,QAAO;AACpE,MAAI,YAAY,UAAU,eAAe,SAAS,WAAY,QAAO;AAErE,SAAO;AACT;AAKO,SAAS,eACd,OACA,UAAwB,CAAC,GACV;AACf,QAAM,cAAc,WAAW,KAAK;AACpC,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,YAAY,aAAa;AAE/B,aAAW,YAAY,WAAW;AAChC,QAAI,CAAC,mBAAmB,UAAU,WAAW,EAAG;AAChD,QAAI,SAAS,YAAY,EAAE,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,GAAG,GAAI;AAElF,WAAO;AAAA,EACT;AACF;AAKO,SAAS,kBACd,OACA,UAAwB,CAAC,GACpB;AACL,QAAM,cAAc,WAAW,KAAK;AACpC,QAAM,EAAE,OAAO,SAAS,IAAI;AAC5B,QAAM,YAAY,aAAa;AAC/B,QAAM,oBAAoB,oBAAI,IAAO;AAErC,aAAW,YAAY,WAAW;AAChC,QAAI,CAAC,mBAAmB,UAAU,WAAW,EAAG;AAChD,QAAI,SAAS,YAAY,EAAE,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,GAAG,GAAI;AAElF,sBAAkB,IAAI,QAAQ;AAAA,EAChC;AAEA,SAAO,MAAM,KAAK,iBAAiB;AACrC;AAKO,SAAS,iBACd,OACA,UAAiC,EAAE,MAAM,KAAK,GAC/B;AACf,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,cAAc,WAAW,KAAK;AACpC,MAAI;AAEJ,mBAAiB,MAAM,CAAC,YAAY;AAClC,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,UAAW,QAAmB;AACpC,QAAI,CAAC,QAAS,QAAO;AAErB,UAAM,WAAW,QAAQ,IAAI,YAAY,IAAI;AAC7C,QACE,YACA,aAAc,gBACd,mBAAmB,UAAU,WAAW,GACxC;AACA,wBAAkB;AAClB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/index.d.ts
CHANGED