@studiometa/js-toolkit 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/Base.d.ts +14 -12
- package/Base/Base.js +17 -16
- package/Base/Base.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.d.ts +2 -2
- package/Base/managers/ChildrenManager.js +4 -4
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/EventsManager.d.ts +10 -10
- package/Base/managers/EventsManager.js +10 -10
- package/Base/managers/EventsManager.js.map +1 -1
- package/Base/managers/ResponsiveOptionsManager.d.ts +6 -6
- package/Base/managers/ResponsiveOptionsManager.js +6 -6
- package/Base/managers/ResponsiveOptionsManager.js.map +1 -1
- package/Base/managers/ServicesManager.d.ts +2 -2
- package/Base/managers/ServicesManager.js +2 -2
- package/Base/managers/ServicesManager.js.map +1 -1
- package/Base/utils.d.ts +3 -2
- package/Base/utils.js +7 -5
- package/Base/utils.js.map +2 -2
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +1 -0
- package/decorators/index.js.map +2 -2
- package/decorators/withBreakpointManager.d.ts +2 -1
- package/decorators/withBreakpointManager.js.map +2 -2
- package/decorators/withBreakpointObserver.d.ts +2 -1
- package/decorators/withBreakpointObserver.js.map +2 -2
- package/decorators/withDrag.d.ts +2 -1
- package/decorators/withDrag.js.map +2 -2
- package/decorators/withExtraConfig.d.ts +2 -1
- package/decorators/withExtraConfig.js.map +2 -2
- package/decorators/withFreezedOptions.d.ts +2 -1
- package/decorators/withFreezedOptions.js.map +2 -2
- package/decorators/withGroup.d.ts +16 -0
- package/decorators/withGroup.js +33 -0
- package/decorators/withGroup.js.map +7 -0
- package/decorators/withIntersectionObserver.d.ts +2 -1
- package/decorators/withIntersectionObserver.js.map +2 -2
- package/decorators/withMountOnMediaQuery.d.ts +2 -1
- package/decorators/withMountOnMediaQuery.js.map +2 -2
- package/decorators/withMountWhenInView.d.ts +2 -1
- package/decorators/withMountWhenInView.js.map +2 -2
- package/decorators/withMountWhenPrefersMotion.d.ts +3 -0
- package/decorators/withMountWhenPrefersMotion.js.map +2 -2
- package/decorators/withMutation.d.ts +2 -1
- package/decorators/withMutation.js.map +2 -2
- package/decorators/withRelativePointer.d.ts +2 -1
- package/decorators/withRelativePointer.js.map +2 -2
- package/decorators/withResponsiveOptions.d.ts +2 -1
- package/decorators/withResponsiveOptions.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.d.ts +2 -1
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/helpers/createApp.d.ts +2 -1
- package/helpers/createApp.js.map +2 -2
- package/helpers/getClosestParent.d.ts +2 -1
- package/helpers/getClosestParent.js.map +2 -2
- package/helpers/getDirectChildren.d.ts +13 -11
- package/helpers/getDirectChildren.js.map +2 -2
- package/helpers/getInstanceFromElement.d.ts +2 -1
- package/helpers/getInstanceFromElement.js +2 -2
- package/helpers/getInstanceFromElement.js.map +2 -2
- package/helpers/importOnInteraction.d.ts +3 -2
- package/helpers/importOnInteraction.js.map +2 -2
- package/helpers/importOnMediaQuery.d.ts +3 -2
- package/helpers/importOnMediaQuery.js.map +2 -2
- package/helpers/importWhenIdle.d.ts +3 -2
- package/helpers/importWhenIdle.js.map +2 -2
- package/helpers/importWhenPrefersMotion.d.ts +3 -2
- package/helpers/importWhenPrefersMotion.js.map +2 -2
- package/helpers/importWhenVisible.d.ts +3 -2
- package/helpers/importWhenVisible.js.map +2 -2
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +1 -0
- package/helpers/index.js.map +2 -2
- package/helpers/registerComponent.d.ts +10 -0
- package/helpers/registerComponent.js +11 -0
- package/helpers/registerComponent.js.map +7 -0
- package/helpers/utils.d.ts +1 -1
- package/helpers/utils.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/index.js.map +2 -2
- package/package.json +1 -1
- package/services/AbstractService.d.ts +1 -1
- package/services/AbstractService.js.map +1 -1
- package/services/DragService.d.ts +3 -2
- package/services/DragService.js +5 -1
- package/services/DragService.js.map +2 -2
- package/services/KeyService.d.ts +2 -1
- package/services/KeyService.js.map +2 -2
- package/services/LoadService.d.ts +2 -1
- package/services/LoadService.js.map +2 -2
- package/services/MutationService.d.ts +2 -1
- package/services/MutationService.js.map +2 -2
- package/services/PointerService.d.ts +2 -1
- package/services/PointerService.js.map +2 -2
- package/services/RafService.d.ts +2 -1
- package/services/RafService.js.map +2 -2
- package/services/ResizeService.d.ts +2 -1
- package/services/ResizeService.js.map +2 -2
- package/services/ScrollService.d.ts +2 -1
- package/services/ScrollService.js.map +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/SmartQueue.js.map +1 -1
- package/utils/cache.d.ts +2 -1
- package/utils/cache.js.map +2 -2
- package/utils/collide/boundingRectToCircle.d.ts +3 -2
- package/utils/collide/boundingRectToCircle.js.map +2 -2
- package/utils/collide/collideCircleCircle.d.ts +3 -2
- package/utils/collide/collideCircleCircle.js.map +2 -2
- package/utils/collide/collideCircleRect.d.ts +3 -2
- package/utils/collide/collideCircleRect.js.map +2 -2
- package/utils/collide/collidePointCircle.d.ts +3 -2
- package/utils/collide/collidePointCircle.js.map +2 -2
- package/utils/collide/collidePointRect.d.ts +3 -2
- package/utils/collide/collidePointRect.js.map +2 -2
- package/utils/collide/collideRectRect.d.ts +3 -2
- package/utils/collide/collideRectRect.js.map +2 -2
- package/utils/css/animate.d.ts +2 -1
- package/utils/css/animate.js.map +2 -2
- package/utils/css/classes.d.ts +6 -3
- package/utils/css/classes.js.map +2 -2
- package/utils/css/getOffsetSizes.d.ts +2 -1
- package/utils/css/getOffsetSizes.js.map +2 -2
- package/utils/css/matrix.d.ts +10 -9
- package/utils/css/matrix.js.map +2 -2
- package/utils/css/styles.d.ts +4 -2
- package/utils/css/styles.js.map +2 -2
- package/utils/css/transform.d.ts +2 -1
- package/utils/css/transform.js.map +2 -2
- package/utils/css/transition.d.ts +3 -2
- package/utils/css/transition.js +1 -1
- package/utils/css/transition.js.map +2 -2
- package/utils/debounce.d.ts +5 -4
- package/utils/debounce.js.map +2 -2
- package/utils/dom/createElement.d.ts +24 -1
- package/utils/dom/createElement.js +8 -2
- package/utils/dom/createElement.js.map +2 -2
- package/utils/getComponentResolver.d.ts +1 -1
- package/utils/getComponentResolver.js.map +1 -1
- package/utils/history.d.ts +17 -14
- package/utils/history.js.map +2 -2
- package/utils/is.d.ts +25 -9
- package/utils/is.js.map +2 -2
- package/utils/keyCodes.d.ts +3 -0
- package/utils/keyCodes.js.map +2 -2
- package/utils/loadElement.d.ts +10 -5
- package/utils/loadElement.js.map +2 -2
- package/utils/math/clamp.d.ts +2 -6
- package/utils/math/clamp.js.map +2 -2
- package/utils/math/clamp01.d.ts +2 -4
- package/utils/math/clamp01.js.map +2 -2
- package/utils/math/createEases.d.ts +13 -5
- package/utils/math/createEases.js.map +2 -2
- package/utils/math/createRange.d.ts +2 -1
- package/utils/math/createRange.js.map +2 -2
- package/utils/math/damp.d.ts +7 -6
- package/utils/math/damp.js.map +2 -2
- package/utils/math/ease.d.ts +23 -14
- package/utils/math/ease.js.map +2 -2
- package/utils/math/inertiaFinalValue.d.ts +6 -5
- package/utils/math/inertiaFinalValue.js.map +2 -2
- package/utils/math/lerp.d.ts +6 -5
- package/utils/math/lerp.js.map +2 -2
- package/utils/math/map.d.ts +3 -2
- package/utils/math/map.js.map +2 -2
- package/utils/math/mean.d.ts +3 -0
- package/utils/math/mean.js.map +2 -2
- package/utils/math/round.d.ts +5 -4
- package/utils/math/round.js.map +2 -2
- package/utils/math/smoothTo.d.ts +2 -1
- package/utils/math/smoothTo.js +3 -7
- package/utils/math/smoothTo.js.map +2 -2
- package/utils/math/spring.d.ts +9 -9
- package/utils/math/spring.js.map +1 -1
- package/utils/math/wrap.d.ts +2 -1
- package/utils/math/wrap.js.map +2 -2
- package/utils/memo.d.ts +2 -1
- package/utils/memo.js.map +2 -2
- package/utils/memoize.d.ts +2 -1
- package/utils/memoize.js.map +2 -2
- package/utils/nextFrame.d.ts +2 -1
- package/utils/nextFrame.js.map +2 -2
- package/utils/nextMicrotask.d.ts +2 -1
- package/utils/nextMicrotask.js.map +2 -2
- package/utils/nextTick.d.ts +2 -1
- package/utils/nextTick.js.map +2 -2
- package/utils/noop.d.ts +1 -1
- package/utils/noop.js.map +1 -1
- package/utils/object/getAllProperties.d.ts +1 -1
- package/utils/object/getAllProperties.js.map +1 -1
- package/utils/random.d.ts +11 -8
- package/utils/random.js.map +2 -2
- package/utils/scheduler.d.ts +6 -1
- package/utils/scheduler.js.map +2 -2
- package/utils/scrollTo.d.ts +3 -2
- package/utils/scrollTo.js.map +2 -2
- package/utils/string/changeCase.d.ts +12 -6
- package/utils/string/changeCase.js.map +2 -2
- package/utils/string/endsWith.d.ts +2 -1
- package/utils/string/endsWith.js.map +2 -2
- package/utils/string/startsWith.d.ts +2 -1
- package/utils/string/startsWith.js.map +2 -2
- package/utils/string/withLeadingCharacters.d.ts +5 -4
- package/utils/string/withLeadingCharacters.js.map +2 -2
- package/utils/string/withLeadingSlash.d.ts +3 -2
- package/utils/string/withLeadingSlash.js.map +2 -2
- package/utils/string/withTrailingCharacters.d.ts +5 -4
- package/utils/string/withTrailingCharacters.js.map +2 -2
- package/utils/string/withTrailingSlash.d.ts +3 -2
- package/utils/string/withTrailingSlash.js.map +2 -2
- package/utils/string/withoutLeadingCharacters.d.ts +5 -4
- package/utils/string/withoutLeadingCharacters.js.map +2 -2
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +5 -4
- package/utils/string/withoutLeadingCharactersRecursive.js.map +2 -2
- package/utils/string/withoutLeadingSlash.d.ts +3 -2
- package/utils/string/withoutLeadingSlash.js.map +2 -2
- package/utils/string/withoutTrailingCharacters.d.ts +5 -4
- package/utils/string/withoutTrailingCharacters.js.map +2 -2
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +5 -4
- package/utils/string/withoutTrailingCharactersRecursive.js.map +2 -2
- package/utils/string/withoutTrailingSlash.d.ts +3 -2
- package/utils/string/withoutTrailingSlash.js.map +2 -2
- package/utils/throttle.d.ts +3 -2
- package/utils/throttle.js.map +2 -2
- package/utils/trapFocus.d.ts +4 -2
- package/utils/trapFocus.js.map +2 -2
- package/utils/tween.d.ts +1 -1
- package/utils/tween.js.map +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountWhenInView.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithMountWhenInViewProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n}\n\nexport interface WithMountWhenInViewInterface extends BaseInterface {\n /**\n * @private\n */\n __isVisible: boolean;\n /**\n * @private\n */\n __observer: IntersectionObserver;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountWhenInView<S extends Base = Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: [0, 1] },\n): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps> {\n /**\n * Class.\n */\n class WithMountWhenInView<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithMountWhenInViewProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n *\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\n *\n * @private\n */\n __observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.__observer = new IntersectionObserver(\n (entries) => {\n const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);\n if (this.__isVisible !== isVisible) {\n this.__isVisible = isVisible;\n\n if (isVisible) {\n this.$mount();\n } else {\n setTimeout(() => this.$destroy());\n }\n }\n },\n {\n ...defaultOptions,\n ...(this.$options as typeof this.$options & WithMountWhenInViewProps['$options'])\n .intersectionObserver,\n },\n );\n\n this.__observer.observe(this.$el);\n\n this.$on('terminated', () => {\n this.__observer.disconnect();\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n async $mount() {\n if (this.__isVisible) {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithMountWhenInViewProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n}\n\nexport interface WithMountWhenInViewInterface extends BaseInterface {\n /**\n * @private\n */\n __isVisible: boolean;\n /**\n * @private\n */\n __observer: IntersectionObserver;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withMountWhenInView.html\n*/\nexport function withMountWhenInView<S extends Base = Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: [0, 1] },\n): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps> {\n /**\n * Class.\n */\n class WithMountWhenInView<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithMountWhenInViewProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n *\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\n *\n * @private\n */\n __observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.__observer = new IntersectionObserver(\n (entries) => {\n const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);\n if (this.__isVisible !== isVisible) {\n this.__isVisible = isVisible;\n\n if (isVisible) {\n this.$mount();\n } else {\n setTimeout(() => this.$destroy());\n }\n }\n },\n {\n ...defaultOptions,\n ...(this.$options as typeof this.$options & WithMountWhenInViewProps['$options'])\n .intersectionObserver,\n },\n );\n\n this.__observer.observe(this.$el);\n\n this.$on('terminated', () => {\n this.__observer.disconnect();\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n async $mount() {\n if (this.__isVisible) {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
+
"mappings": "AAyBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;AAAA,EAI1E,MAAM,4BAA6D,UAEjE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,SAAS;AAAA,QACP,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,aAAa,IAAI;AAAA,QACpB,CAAC,YAAY;AACX,gBAAM,YAAY,QAAQ,OAAO,CAAC,KAAK,UAAU,OAAO,MAAM,gBAAgB,KAAK;AACnF,cAAI,KAAK,gBAAgB,WAAW;AAClC,iBAAK,cAAc;AAEnB,gBAAI,WAAW;AACb,mBAAK,OAAO;AAAA,YACd,OAAO;AACL,yBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,YAClC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SACN;AAAA,QACL;AAAA,MACF;AAEA,WAAK,WAAW,QAAQ,KAAK,GAAG;AAEhC,WAAK,IAAI,cAAc,MAAM;AAC3B,aAAK,WAAW,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,SAAS;AACb,UAAI,KAAK,aAAa;AACpB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { Base } from '../Base/index.js';
|
|
2
2
|
import { BaseDecorator, BaseInterface } from '../Base/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withMountWhenPrefersMotion.html
|
|
5
|
+
*/
|
|
3
6
|
export declare function withMountWhenPrefersMotion<S extends Base = Base>(BaseClass: typeof Base): BaseDecorator<BaseInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountWhenPrefersMotion.ts"],
|
|
4
|
-
"sourcesContent": ["import { withMountOnMediaQuery } from './withMountOnMediaQuery.js';\nimport type { Base } from '../Base/index.js';\nimport { BaseDecorator, BaseInterface } from '../Base/types.js';\n\nexport function withMountWhenPrefersMotion<S extends Base = Base>(\n BaseClass: typeof Base,\n): BaseDecorator<BaseInterface, S> {\n return withMountOnMediaQuery(BaseClass, 'not (prefers-reduced-motion)');\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,6BAA6B;
|
|
4
|
+
"sourcesContent": ["import { withMountOnMediaQuery } from './withMountOnMediaQuery.js';\nimport type { Base } from '../Base/index.js';\nimport { BaseDecorator, BaseInterface } from '../Base/types.js';\n\n/**\n * @link https://js-toolkit.studiometa.dev/api/decorators/withMountWhenPrefersMotion.html\n */\nexport function withMountWhenPrefersMotion<S extends Base = Base>(\n BaseClass: typeof Base,\n): BaseDecorator<BaseInterface, S> {\n return withMountOnMediaQuery(BaseClass, 'not (prefers-reduced-motion)');\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,6BAA6B;AAO/B,SAAS,2BACd,WACiC;AACjC,SAAO,sBAAsB,WAAW,8BAA8B;AACxE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,5 +9,6 @@ export interface WithMutationInterface extends BaseInterface {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Add a mutation observer to a component.
|
|
12
|
-
|
|
12
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withMutation.html
|
|
13
|
+
*/
|
|
13
14
|
export declare function withMutation<S extends Base>(BaseClass: typeof Base, { target, ...options }?: MutationDecoratorOptions): BaseDecorator<BaseInterface, S>;
|
|
@@ -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 */\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
|
-
"mappings": "AAGA,SAAS,mBAAmB;
|
|
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
|
+
"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
|
}
|
|
@@ -9,5 +9,6 @@ export interface RelativePointerInterface extends BaseInterface {
|
|
|
9
9
|
}
|
|
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
|
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 */\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
|
-
"mappings": "AAGA,SAAS,kBAAkB;
|
|
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
|
+
"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
|
}
|
|
@@ -2,7 +2,8 @@ import type { BaseInterface, BaseDecorator } from '../Base/types.js';
|
|
|
2
2
|
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
|
export declare function withResponsiveOptions<S extends Base>(BaseClass: typeof Base, { responsiveOptions }?: {
|
|
7
8
|
responsiveOptions?: any[];
|
|
8
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 */\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
|
-
"mappings": "AAGA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,WAAW,gBAAgB;
|
|
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
|
+
"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
|
}
|
|
@@ -52,5 +52,6 @@ export interface WithScrolledInViewInterface extends BaseInterface {
|
|
|
52
52
|
}
|
|
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
|
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 */\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
|
-
"mappings": "AAOA,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,OACX;AACP,SAAS,iBAAiB,gBAAgB;AAyC1C,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,WAAW,EAAE,IAAI,IACrB,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAChC,IACA;AAAA,KACG,MAAM,UAAU,EAAE,IAAI,IAAI,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,MAAM,IAAI;AAAA,EACrF;AACR;AAKA,SAAS,YACP,OACA,YACA,eACA,OAAkB,KACZ;AACN,QAAM,QAAQ,IAAI,IAAI,MAAM,UAAU,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,MAAM,IAAI,GAAG,MAAM,IAAI,IAAI,CAAC;AACzF,QAAM,cAAc,IAAI,IAAI;AAAA,IAC1B,MAAM,QAAQ,IAAI;AAAA,IAClB,MAAM,cAAc,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AACA,iBAAe,OAAO,MAAM,YAAY,SAAS;AACjD,iBAAe,OAAO,MAAM,kBAAkB,eAAe;AAC/D;
|
|
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
|
+
"mappings": "AAOA,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,OACX;AACP,SAAS,iBAAiB,gBAAgB;AAyC1C,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,WAAW,EAAE,IAAI,IACrB,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAChC,IACA;AAAA,KACG,MAAM,UAAU,EAAE,IAAI,IAAI,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,MAAM,IAAI;AAAA,EACrF;AACR;AAKA,SAAS,YACP,OACA,YACA,eACA,OAAkB,KACZ;AACN,QAAM,QAAQ,IAAI,IAAI,MAAM,UAAU,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,MAAM,IAAI,GAAG,MAAM,IAAI,IAAI,CAAC;AACzF,QAAM,cAAc,IAAI,IAAI;AAAA,IAC1B,MAAM,QAAQ,IAAI;AAAA,IAClB,MAAM,cAAc,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AACA,iBAAe,OAAO,MAAM,YAAY,SAAS;AACjD,iBAAe,OAAO,MAAM,kBAAkB,eAAe;AAC/D;AAoBO,SAAS,mBACd,WACA,UAAqC,CAAC,GACkC;AAAA,EAIxE,MAAM,2BAA4D;AAAA,IAChE;AAAA,IACA;AAAA,EACF,EAA+B;AAAA;AAAA;AAAA;AAAA,IAI7B,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,OAAO,CAAC,gBAAgB;AAAA,MACxB,SAAS;AAAA,QACP,YAAY;AAAA,UACV,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,QACA,eAAe;AAAA,UACb,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,QACA,QAAQ;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,IAEA,UAA6B;AAAA,MAC3B,OAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,KAAK;AAAA,QACH,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,SAAS;AAAA,QACP,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,eAAe;AAAA,QACb,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA,gBAAgB;AAAA,QACd,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,IACF;AAAA,IAEA,sBAAsB;AAAA,IAEtB,IAAI,QAAQ;AACV,UAAI,KAAK,qBAAqB;AAC5B,aAAK,sBAAsB;AAC3B,cAAM,cAAc,QAAQ,iBACxB,eAAe,KAAK,GAAG,IACvB,KAAK,IAAI,sBAAsB;AAEnC,oBAAY,KAAK,OAAO;AACxB,oBAAY,KAAK,OAAO;AAExB,cAAM,iBAAiB;AAAA,UACrB,GAAG;AAAA,UACH,GAAG;AAAA,UACH,QAAQ,OAAO;AAAA,UACf,OAAO,OAAO;AAAA,QAChB;AAEA,cAAM,SAAS,gBAAgB,KAAK,SAAS,MAAM;AAGnD,cAAM,CAAC,QAAQ,IAAI,IAAI,SAAS,KAAK,aAAa,gBAAgB,MAAM;AACxE,cAAM,WAAW,MAAM,OAAO,SAAS,QAAQ,IAAI;AACnD,cAAM,YAAY,WAAW,OAAO,IAAI,SAAS,WAAW,WAAW,OAAO,OAAO;AAErF,cAAM,CAAC,QAAQ,IAAI,IAAI,SAAS,KAAK,aAAa,gBAAgB,MAAM;AACxE,cAAM,WAAW,MAAM,OAAO,SAAS,QAAQ,IAAI;AACnD,cAAM,YAAY,WAAW,OAAO,IAAI,SAAS,WAAW,WAAW,OAAO,OAAO;AAErF,aAAK,QAAQ,MAAM,IAAI;AACvB,aAAK,QAAQ,MAAM,IAAI;AACvB,aAAK,QAAQ,IAAI,IAAI;AACrB,aAAK,QAAQ,IAAI,IAAI;AACrB,aAAK,QAAQ,QAAQ,IAAI;AACzB,aAAK,QAAQ,QAAQ,IAAI;AACzB,aAAK,QAAQ,cAAc,IAAI;AAC/B,aAAK,QAAQ,cAAc,IAAI;AAC/B,aAAK,QAAQ,SAAS,IAAI;AAC1B,aAAK,QAAQ,SAAS,IAAI;AAC1B,aAAK,QAAQ,eAAe,IAAI;AAChC,aAAK,QAAQ,eAAe,IAAI;AAAA,MAClC;AAEA,aAAO,KAAK;AAAA,IACd;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,YAAM,SAAS,MAAM;AACnB,kBAAU,KAAK,MAAM;AAEnB,gBAAM,WAAW,KAAK,aAAa,kBAAkB,KAAK,KAAK;AAC/D,cAAI,WAAW,QAAQ,GAAG;AACxB,sBAAU,MAAM,MAAM;AACpB,uBAAS,KAAK,OAAO;AAAA,YACvB,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAEA,YAAM,WAAW;AAAA,QACf,YAAY,OAAoB;AAC9B,mBAAS,MAAM,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC;AAAA,QACtC;AAAA,QACA,SAAS,MAAM;AACb,eAAK,sBAAsB;AAC3B,iBAAO;AAAA,QACT;AAAA,QACA,UAAU,CAAC,UAA8B;AACvC,cAAI,MAAM,QAAQ,KAAK,MAAM,QAAQ,GAAG;AACtC,iBAAK,UAAU,OAAO,QAAQ;AAAA,UAChC;AAAA,QACF;AAAA,QACA,SAAS,MAAM,OAAO;AAAA,QACtB,QAAQ,MAAM;AACZ,gBAAM,EAAE,YAAY,cAAc,IAAI,KAAK;AAC3C,sBAAY,KAAK,SAAS,YAAY,eAAe,GAAG;AACxD,sBAAY,KAAK,SAAS,YAAY,eAAe,GAAG;AAExD,cACE,KAAK,QAAQ,cAAc,MAAM,KAAK,QAAQ,QAAQ,KACtD,KAAK,QAAQ,cAAc,MAAM,KAAK,QAAQ,QAAQ,GACtD;AACA,iBAAK,UAAU,QAAQ,QAAQ;AAAA,UACjC;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,WAAK,IAAI,kBAAkB,MAAM;AAC/B,aAAK,IAAI,WAAW,QAAQ;AAC5B,aAAK,IAAI,WAAW,QAAQ;AAC5B,aAAK,IAAI,YAAY,QAAQ;AAC7B,aAAK,IAAI,UAAU,QAAQ;AAAA,MAC7B,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,KAAK,WAAW,QAAQ;AAC7B,aAAK,KAAK,WAAW,QAAQ;AAC7B,aAAK,KAAK,YAAY,QAAQ;AAC9B,aAAK,KAAK,UAAU,QAAQ;AAG5B,aAAK,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ;AACpD,aAAK,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ;AACpD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/createApp.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export type CreateAppOptions = Partial<Features> & {
|
|
|
6
6
|
/**
|
|
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
|
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.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 { getInstances } from '../Base/index.js';\nimport { features } from '../Base/features.js';\nimport { useMutation } from '../services/index.js';\nimport { isBoolean, isObject, isString } from '../utils/index.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 */\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 {\n root = document.body,\n breakpoints = null,\n blocking = null,\n prefix = null,\n attributes = null,\n } = options instanceof HTMLElement ? { root: options } : options;\n\n if (isObject(breakpoints)) {\n features.set('breakpoints', breakpoints);\n }\n\n if (isBoolean(blocking)) {\n features.set('blocking', blocking);\n }\n\n if (isString(prefix)) {\n features.set('prefix', prefix);\n }\n\n if (isObject(attributes)) {\n features.set('attributes', attributes);\n }\n\n // Terminate components whose root element has been removed from the DOM\n const service = useMutation(document.documentElement, { childList: true, subtree: true });\n const symbol = Symbol('createApp');\n service.add(symbol, (props) => {\n for (const mutation of props.mutations) {\n if (mutation.type === 'childList') {\n for (const node of mutation.removedNodes) {\n if (!node.isConnected) {\n for (const instance of getInstances()) {\n if (node === instance.$el || node.contains(instance.$el)) {\n instance.$terminate();\n }\n }\n }\n }\n }\n }\n });\n\n async function init() {\n app = new App(root) as S & Base<T>;\n await app.$mount();\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,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,WAAW,UAAU,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { getInstances } from '../Base/index.js';\nimport { features } from '../Base/features.js';\nimport { useMutation } from '../services/index.js';\nimport { isBoolean, isObject, isString } from '../utils/index.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 {\n root = document.body,\n breakpoints = null,\n blocking = null,\n prefix = null,\n attributes = null,\n } = options instanceof HTMLElement ? { root: options } : options;\n\n if (isObject(breakpoints)) {\n features.set('breakpoints', breakpoints);\n }\n\n if (isBoolean(blocking)) {\n features.set('blocking', blocking);\n }\n\n if (isString(prefix)) {\n features.set('prefix', prefix);\n }\n\n if (isObject(attributes)) {\n features.set('attributes', attributes);\n }\n\n // Terminate components whose root element has been removed from the DOM\n const service = useMutation(document.documentElement, { childList: true, subtree: true });\n const symbol = Symbol('createApp');\n service.add(symbol, (props) => {\n for (const mutation of props.mutations) {\n if (mutation.type === 'childList') {\n for (const node of mutation.removedNodes) {\n if (!node.isConnected) {\n for (const instance of getInstances()) {\n if (node === instance.$el || node.contains(instance.$el)) {\n instance.$terminate();\n }\n }\n }\n }\n }\n }\n });\n\n async function init() {\n app = new App(root) as S & Base<T>;\n await app.$mount();\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,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,WAAW,UAAU,gBAAgB;AAWvC,SAAS,UACd,KACA,UAA0C,CAAC,GACf;AAC5B,MAAI;AACJ,QAAM;AAAA,IACJ,OAAO,SAAS;AAAA,IAChB,cAAc;AAAA,IACd,WAAW;AAAA,IACX,SAAS;AAAA,IACT,aAAa;AAAA,EACf,IAAI,mBAAmB,cAAc,EAAE,MAAM,QAAQ,IAAI;AAEzD,MAAI,SAAS,WAAW,GAAG;AACzB,aAAS,IAAI,eAAe,WAAW;AAAA,EACzC;AAEA,MAAI,UAAU,QAAQ,GAAG;AACvB,aAAS,IAAI,YAAY,QAAQ;AAAA,EACnC;AAEA,MAAI,SAAS,MAAM,GAAG;AACpB,aAAS,IAAI,UAAU,MAAM;AAAA,EAC/B;AAEA,MAAI,SAAS,UAAU,GAAG;AACxB,aAAS,IAAI,cAAc,UAAU;AAAA,EACvC;AAGA,QAAM,UAAU,YAAY,SAAS,iBAAiB,EAAE,WAAW,MAAM,SAAS,KAAK,CAAC;AACxF,QAAM,SAAS,OAAO,WAAW;AACjC,UAAQ,IAAI,QAAQ,CAAC,UAAU;AAC7B,eAAW,YAAY,MAAM,WAAW;AACtC,UAAI,SAAS,SAAS,aAAa;AACjC,mBAAW,QAAQ,SAAS,cAAc;AACxC,cAAI,CAAC,KAAK,aAAa;AACrB,uBAAW,YAAY,aAAa,GAAG;AACrC,kBAAI,SAAS,SAAS,OAAO,KAAK,SAAS,SAAS,GAAG,GAAG;AACxD,yBAAS,WAAW;AAAA,cACtB;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,iBAAe,OAAO;AACpB,UAAM,IAAI,IAAI,IAAI;AAClB,UAAM,IAAI,OAAO;AACjB,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
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
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 */\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
|
-
"mappings": "AACA,SAAS,8BAA8B;AACvC,SAAS,wBAAwB;
|
|
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
|
+
"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
|
}
|
|
@@ -3,19 +3,21 @@ import { Base } from '../Base/index.js';
|
|
|
3
3
|
* Get direct children from a parent when working with nested components.
|
|
4
4
|
*
|
|
5
5
|
* @template {Base} T
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
10
|
-
|
|
6
|
+
* @param {Base} parentInstance
|
|
7
|
+
* @param {string} parentName
|
|
8
|
+
* @param {string} childrenName
|
|
9
|
+
* @return {T[]}
|
|
10
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/getDirectChildren.html
|
|
11
|
+
*/
|
|
11
12
|
export declare function getDirectChildren<T extends Base = Base>(parentInstance: Base, parentName: string, childrenName: string): T[];
|
|
12
13
|
/**
|
|
13
14
|
* Test if a component instance is a direct child from the given component.
|
|
14
15
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @
|
|
20
|
-
|
|
16
|
+
* @param {Base} parentInstance
|
|
17
|
+
* @param {string} parentName
|
|
18
|
+
* @param {string} childrenName
|
|
19
|
+
* @param {Base} childInstance
|
|
20
|
+
* @return {boolean}
|
|
21
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/isDirectChild.html
|
|
22
|
+
*/
|
|
21
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
|
|
5
|
-
"mappings": "AACA,SAAS,eAAe;
|
|
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 children = parentInstance.$children[childrenName] as Base<BaseProps>[];\n const nestedParents = parentInstance.$children[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[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
|
+
"mappings": "AACA,SAAS,eAAe;AAYjB,SAAS,kBACd,gBACA,YACA,cACK;AACL,QAAM,WAAW,eAAe,UAAU,YAAY;AACtD,QAAM,gBAAgB,eAAe,UAAU,UAAU;AAEzD,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,UAAU,YAAY;AAE1D,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
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
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
|
export declare function getInstanceFromElement<T extends BaseConstructor>(element: BaseEl, Constructor: T): InstanceType<T> | null;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
function getInstanceFromElement(element, Constructor) {
|
|
2
|
-
if (!element || !element.__base__ || !element.__base__.has(Constructor)) {
|
|
2
|
+
if (!element || !element.__base__ || !element.__base__.has(Constructor.config.name)) {
|
|
3
3
|
return null;
|
|
4
4
|
}
|
|
5
|
-
return element.__base__.get(Constructor);
|
|
5
|
+
return element.__base__.get(Constructor.config.name);
|
|
6
6
|
}
|
|
7
7
|
export {
|
|
8
8
|
getInstanceFromElement
|
|
@@ -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 */\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)) {\n return null;\n }\n\n return element.__base__.get(Constructor) as InstanceType<T>;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
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
|
+
"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
|
}
|
|
@@ -11,8 +11,9 @@ import type { Base, BaseConstructor } from '../Base/index.js';
|
|
|
11
11
|
* The events to listen to to trigger the import.
|
|
12
12
|
* @param {Base} [parent]
|
|
13
13
|
* The parent component.
|
|
14
|
-
* @
|
|
15
|
-
|
|
14
|
+
* @return {Promise<InstanceType<T>>}
|
|
15
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/importOnInteraction.html
|
|
16
|
+
*/
|
|
16
17
|
export declare function importOnInteraction<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
17
18
|
default: T;
|
|
18
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 * @
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,UAAU,4BAA4B;
|
|
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
|
+
"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
|
}
|
|
@@ -7,8 +7,9 @@ import type { BaseConstructor } from '../Base/index.js';
|
|
|
7
7
|
* The import function.
|
|
8
8
|
* @param {string} media
|
|
9
9
|
* The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)
|
|
10
|
-
* @
|
|
11
|
-
|
|
10
|
+
* @return {Promise<T>}
|
|
11
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/importOnMediaQuery.html
|
|
12
|
+
*/
|
|
12
13
|
export declare function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
13
14
|
default: T;
|
|
14
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 * @
|
|
5
|
-
"mappings": "AACA,SAAS,4BAA4B;
|
|
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
|
+
"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
|
}
|
|
@@ -10,8 +10,9 @@ type ImportWhenIdleOptions = {
|
|
|
10
10
|
* The import function.
|
|
11
11
|
* @param {ImportWhenIdleOptions} [options]
|
|
12
12
|
* The time to wait before triggering the callback if never idle.
|
|
13
|
-
* @
|
|
14
|
-
|
|
13
|
+
* @return {Promise<T>}
|
|
14
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/importWhenIdle.html
|
|
15
|
+
*/
|
|
15
16
|
export declare function importWhenIdle<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
16
17
|
default: T;
|
|
17
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 * @
|
|
5
|
-
"mappings": "AACA,SAAS,4BAA4B;
|
|
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
|
+
"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
|
}
|
|
@@ -4,8 +4,9 @@ import type { BaseConstructor } from '../Base/index.js';
|
|
|
4
4
|
*
|
|
5
5
|
* @template {BaseConstructor} T
|
|
6
6
|
* @param {() => Promise<T|{default:T}>} fn
|
|
7
|
-
* @
|
|
8
|
-
|
|
7
|
+
* @return {Promise<T>}
|
|
8
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/importWhenPrefersMotion.html
|
|
9
|
+
*/
|
|
9
10
|
export declare function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
10
11
|
default: T;
|
|
11
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 * @
|
|
5
|
-
"mappings": "AACA,SAAS,0BAA0B;
|
|
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
|
+
"mappings": "AACA,SAAS,0BAA0B;AAU5B,SAAS,wBACd,IACY;AACZ,SAAO,mBAAmB,IAAI,8BAA8B;AAC9D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,8 +11,9 @@ import type { Base, BaseConstructor } from '../Base/index.js';
|
|
|
11
11
|
* The parent component.
|
|
12
12
|
* @param {IntersectionObserverInit} [observerOptions]
|
|
13
13
|
* Options for the `IntersectionObserver` instance.
|
|
14
|
-
* @
|
|
15
|
-
|
|
14
|
+
* @return {Promise<T>}
|
|
15
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html
|
|
16
|
+
*/
|
|
16
17
|
export declare function importWhenVisible<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
|
|
17
18
|
default: T;
|
|
18
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 * @
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;
|
|
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
|
+
"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
package/helpers/index.js
CHANGED
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 './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';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './createApp.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';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseConstructor } from '../Base/Base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Register globally and mount a given component, or a promise resolving to a component.
|
|
4
|
+
*
|
|
5
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/registerComponent.html
|
|
6
|
+
* @param ctor The component constructor or a promise resolving to it.
|
|
7
|
+
* @param nameOrSelector The name or selector to used for this component.
|
|
8
|
+
* @return A promise resolving to an array of mounted component instances.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerComponent<T extends BaseConstructor = BaseConstructor>(ctor: T | Promise<T>, nameOrSelector?: string): Promise<Awaited<InstanceType<T>>[]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
async function registerComponent(ctor, nameOrSelector) {
|
|
2
|
+
if (ctor instanceof Promise) {
|
|
3
|
+
ctor = await ctor;
|
|
4
|
+
}
|
|
5
|
+
const instances = await Promise.all(ctor.$register(nameOrSelector));
|
|
6
|
+
return instances;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
registerComponent
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=registerComponent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/helpers/registerComponent.ts"],
|
|
4
|
+
"sourcesContent": ["import { BaseConstructor } from '../Base/Base.js';\n\n/**\n * Register globally and mount a given component, or a promise resolving to a component.\n *\n * @link https://js-toolkit.studiometa.dev/api/helpers/registerComponent.html\n * @param ctor The component constructor or a promise resolving to it.\n * @param nameOrSelector The name or selector to used for this component.\n * @return A promise resolving to an array of mounted component instances.\n */\nexport async function registerComponent<T extends BaseConstructor = BaseConstructor>(\n ctor: T | Promise<T>,\n nameOrSelector?: string,\n) {\n if (ctor instanceof Promise) {\n ctor = await ctor;\n }\n\n const instances = await Promise.all(ctor.$register(nameOrSelector));\n return instances;\n}\n"],
|
|
5
|
+
"mappings": "AAUA,eAAsB,kBACpB,MACA,gBACA;AACA,MAAI,gBAAgB,SAAS;AAC3B,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,YAAY,MAAM,QAAQ,IAAI,KAAK,UAAU,cAAc,CAAC;AAClE,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/helpers/utils.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* The original selector or element, or list of elements.
|
|
6
6
|
* @param {HTMLElement} [context]
|
|
7
7
|
* The optional context to use to query for elements.
|
|
8
|
-
* @
|
|
8
|
+
* @return {HTMLElement[]} A normalized list of elements.
|
|
9
9
|
*/
|
|
10
10
|
export declare function getTargetElements(nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], context: HTMLElement): HTMLElement[];
|