@studiometa/js-toolkit 2.10.3 → 2.12.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.cjs +155 -60
- package/Base/Base.cjs.map +2 -2
- package/Base/Base.d.ts +1 -1
- package/Base/Base.js +138 -38
- package/Base/Base.js.map +2 -2
- package/Base/managers/AbstractManager.cjs +21 -0
- package/Base/managers/AbstractManager.cjs.map +2 -2
- package/Base/managers/AbstractManager.d.ts +1 -0
- package/Base/managers/AbstractManager.js +21 -0
- package/Base/managers/AbstractManager.js.map +2 -2
- package/Base/managers/ChildrenManager.cjs +41 -8
- package/Base/managers/ChildrenManager.cjs.map +3 -3
- package/Base/managers/ChildrenManager.js +41 -8
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/EventsManager.cjs +94 -9
- package/Base/managers/EventsManager.cjs.map +2 -2
- package/Base/managers/EventsManager.d.ts +1 -0
- package/Base/managers/EventsManager.js +90 -9
- package/Base/managers/EventsManager.js.map +2 -2
- package/Base/managers/OptionsManager.cjs +29 -2
- package/Base/managers/OptionsManager.cjs.map +2 -2
- package/Base/managers/OptionsManager.d.ts +1 -0
- package/Base/managers/OptionsManager.js +25 -2
- package/Base/managers/OptionsManager.js.map +2 -2
- package/Base/managers/RefsManager.cjs +32 -5
- package/Base/managers/RefsManager.cjs.map +2 -2
- package/Base/managers/RefsManager.d.ts +1 -1
- package/Base/managers/RefsManager.js +40 -6
- package/Base/managers/RefsManager.js.map +2 -2
- package/Base/managers/ResponsiveOptionsManager.cjs +22 -6
- package/Base/managers/ResponsiveOptionsManager.cjs.map +2 -2
- package/Base/managers/ResponsiveOptionsManager.js +22 -6
- package/Base/managers/ResponsiveOptionsManager.js.map +2 -2
- package/Base/managers/ServicesManager.cjs +54 -4
- package/Base/managers/ServicesManager.cjs.map +2 -2
- package/Base/managers/ServicesManager.js +54 -4
- package/Base/managers/ServicesManager.js.map +2 -2
- package/Base/utils.cjs +4 -0
- package/Base/utils.cjs.map +2 -2
- package/Base/utils.d.ts +1 -0
- package/Base/utils.js +4 -0
- package/Base/utils.js.map +2 -2
- package/decorators/index.cjs +3 -2
- package/decorators/index.cjs.map +2 -2
- package/decorators/index.d.ts +3 -2
- package/decorators/index.js +3 -2
- package/decorators/index.js.map +2 -2
- package/decorators/withBreakpointManager.cjs +14 -4
- package/decorators/withBreakpointManager.cjs.map +2 -2
- package/decorators/withBreakpointManager.js +14 -4
- package/decorators/withBreakpointManager.js.map +2 -2
- package/decorators/withBreakpointObserver.cjs +11 -1
- package/decorators/withBreakpointObserver.cjs.map +2 -2
- package/decorators/withBreakpointObserver.js +12 -2
- package/decorators/withBreakpointObserver.js.map +2 -2
- package/decorators/withDrag.cjs +6 -0
- package/decorators/withDrag.cjs.map +1 -1
- package/decorators/withDrag.js +6 -0
- package/decorators/withDrag.js.map +1 -1
- package/decorators/withExtraConfig.cjs +7 -0
- package/decorators/withExtraConfig.cjs.map +1 -1
- package/decorators/withExtraConfig.js +3 -0
- package/decorators/withExtraConfig.js.map +1 -1
- package/decorators/withFreezedOptions.cjs +8 -0
- package/decorators/withFreezedOptions.cjs.map +2 -2
- package/decorators/withFreezedOptions.js +8 -0
- package/decorators/withFreezedOptions.js.map +2 -2
- package/decorators/withIntersectionObserver.cjs +10 -1
- package/decorators/withIntersectionObserver.cjs.map +2 -2
- package/decorators/withIntersectionObserver.js +10 -1
- package/decorators/withIntersectionObserver.js.map +2 -2
- package/decorators/withMountOnMediaQuery.cjs +16 -0
- package/decorators/withMountOnMediaQuery.cjs.map +2 -2
- package/decorators/withMountOnMediaQuery.js +16 -0
- package/decorators/withMountOnMediaQuery.js.map +2 -2
- package/decorators/withMountWhenInView.cjs +21 -0
- package/decorators/withMountWhenInView.cjs.map +2 -2
- package/decorators/withMountWhenInView.js +21 -0
- package/decorators/withMountWhenInView.js.map +2 -2
- package/decorators/withRelativePointer.cjs +56 -0
- package/decorators/withRelativePointer.cjs.map +7 -0
- package/decorators/withRelativePointer.d.ts +13 -0
- package/decorators/withRelativePointer.js +34 -0
- package/decorators/withRelativePointer.js.map +7 -0
- package/decorators/withResponsiveOptions.cjs +3 -0
- package/decorators/withResponsiveOptions.cjs.map +1 -1
- package/decorators/withResponsiveOptions.js +3 -0
- package/decorators/withResponsiveOptions.js.map +1 -1
- package/decorators/withScrolledInView/utils.cjs +6 -6
- package/decorators/withScrolledInView/utils.cjs.map +2 -2
- package/decorators/withScrolledInView/utils.js +7 -7
- package/decorators/withScrolledInView/utils.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.cjs +33 -0
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.js +33 -0
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/decorators/withVue2.cjs +3 -0
- package/decorators/withVue2.cjs.map +1 -1
- package/decorators/withVue2.js +3 -0
- package/decorators/withVue2.js.map +1 -1
- package/helpers/createApp.cjs +2 -2
- package/helpers/createApp.cjs.map +2 -2
- package/helpers/createApp.js +2 -2
- package/helpers/createApp.js.map +2 -2
- package/helpers/getClosestParent.cjs +4 -0
- package/helpers/getClosestParent.cjs.map +1 -1
- package/helpers/getDirectChildren.cjs.map +1 -1
- package/helpers/getDirectChildren.js.map +1 -1
- package/helpers/importOnInteraction.cjs +4 -4
- package/helpers/importOnInteraction.cjs.map +2 -2
- package/helpers/importOnInteraction.js +4 -4
- package/helpers/importOnInteraction.js.map +2 -2
- package/helpers/importWhenPrefersMotion.cjs +4 -0
- package/helpers/importWhenPrefersMotion.cjs.map +1 -1
- package/helpers/importWhenVisible.cjs +2 -1
- package/helpers/importWhenVisible.cjs.map +2 -2
- package/helpers/importWhenVisible.js +2 -1
- package/helpers/importWhenVisible.js.map +2 -2
- package/helpers/index.cjs +4 -0
- package/helpers/index.cjs.map +1 -1
- package/package.json +5 -2
- package/services/drag.cjs +12 -8
- package/services/drag.cjs.map +2 -2
- package/services/drag.js +8 -8
- package/services/drag.js.map +2 -2
- package/services/index.cjs +4 -0
- package/services/index.cjs.map +1 -1
- package/services/key.cjs +6 -2
- package/services/key.cjs.map +2 -2
- package/services/key.js +2 -2
- package/services/key.js.map +2 -2
- package/services/load.cjs +3 -0
- package/services/load.cjs.map +2 -2
- package/services/load.js +3 -0
- package/services/load.js.map +2 -2
- package/services/pointer.cjs +33 -20
- package/services/pointer.cjs.map +3 -3
- package/services/pointer.d.ts +1 -3
- package/services/pointer.js +33 -20
- package/services/pointer.js.map +3 -3
- package/services/raf.cjs +2 -2
- package/services/raf.cjs.map +2 -2
- package/services/raf.js +2 -2
- package/services/raf.js.map +2 -2
- package/services/resize.cjs +4 -0
- package/services/resize.cjs.map +1 -1
- package/services/scroll.cjs +4 -0
- package/services/scroll.cjs.map +1 -1
- package/services/service.cjs +2 -2
- package/services/service.cjs.map +2 -2
- package/services/service.js +2 -2
- package/services/service.js.map +2 -2
- package/utils/Queue.cjs +30 -0
- package/utils/Queue.cjs.map +1 -1
- package/utils/Queue.js +30 -0
- package/utils/Queue.js.map +1 -1
- package/utils/SmartQueue.cjs +16 -0
- package/utils/SmartQueue.cjs.map +2 -2
- package/utils/SmartQueue.js +12 -0
- package/utils/SmartQueue.js.map +2 -2
- package/utils/collide/collidePointRect.cjs +4 -1
- package/utils/collide/collidePointRect.cjs.map +1 -1
- package/utils/collide/collidePointRect.js +4 -1
- package/utils/collide/collidePointRect.js.map +1 -1
- package/utils/collide/collideRectRect.cjs +4 -1
- package/utils/collide/collideRectRect.cjs.map +1 -1
- package/utils/collide/collideRectRect.js +4 -1
- package/utils/collide/collideRectRect.js.map +1 -1
- package/utils/collide/index.cjs +4 -0
- package/utils/collide/index.cjs.map +1 -1
- package/utils/css/animate.cjs +21 -12
- package/utils/css/animate.cjs.map +2 -2
- package/utils/css/animate.js +17 -12
- package/utils/css/animate.js.map +2 -2
- package/utils/css/classes.cjs +2 -3
- package/utils/css/classes.cjs.map +2 -2
- package/utils/css/classes.js +2 -3
- package/utils/css/classes.js.map +2 -2
- package/utils/css/index.cjs +4 -0
- package/utils/css/index.cjs.map +1 -1
- package/utils/css/matrix.cjs.map +1 -1
- package/utils/css/matrix.js.map +1 -1
- package/utils/css/styles.cjs +2 -2
- package/utils/css/styles.cjs.map +2 -2
- package/utils/css/styles.js +2 -2
- package/utils/css/styles.js.map +2 -2
- package/utils/css/transform.cjs.map +1 -1
- package/utils/css/transform.js.map +1 -1
- package/utils/css/transition.cjs +19 -0
- package/utils/css/transition.cjs.map +2 -2
- package/utils/css/transition.js +15 -0
- package/utils/css/transition.js.map +2 -2
- package/utils/focusTrap.cjs +4 -0
- package/utils/focusTrap.cjs.map +2 -2
- package/utils/focusTrap.d.ts +1 -0
- package/utils/focusTrap.js.map +2 -2
- package/utils/history.cjs +6 -5
- package/utils/history.cjs.map +2 -2
- package/utils/history.js +6 -5
- package/utils/history.js.map +2 -2
- package/utils/index.cjs +4 -0
- package/utils/index.cjs.map +1 -1
- package/utils/math/clamp.cjs.map +2 -2
- package/utils/math/clamp.d.ts +1 -0
- package/utils/math/clamp.js.map +2 -2
- package/utils/math/clamp01.cjs +4 -0
- package/utils/math/clamp01.cjs.map +2 -2
- package/utils/math/clamp01.d.ts +1 -0
- package/utils/math/clamp01.js.map +2 -2
- package/utils/math/index.cjs +4 -0
- package/utils/math/index.cjs.map +1 -1
- package/utils/math/inertiaFinalValue.cjs +4 -0
- package/utils/math/inertiaFinalValue.cjs.map +1 -1
- package/utils/nextFrame.cjs.map +2 -2
- package/utils/nextFrame.d.ts +1 -0
- package/utils/nextFrame.js.map +2 -2
- package/utils/noop.cjs.map +2 -2
- package/utils/noop.d.ts +1 -0
- package/utils/noop.js.map +2 -2
- package/utils/object/autoBind.cjs +11 -5
- package/utils/object/autoBind.cjs.map +2 -2
- package/utils/object/autoBind.js +7 -5
- package/utils/object/autoBind.js.map +2 -2
- package/utils/object/index.cjs +4 -0
- package/utils/object/index.cjs.map +1 -1
- package/utils/scheduler.cjs +4 -4
- package/utils/scheduler.cjs.map +2 -2
- package/utils/scheduler.js +4 -4
- package/utils/scheduler.js.map +2 -2
- package/utils/scrollTo.cjs +4 -0
- package/utils/scrollTo.cjs.map +2 -2
- package/utils/scrollTo.d.ts +1 -0
- package/utils/scrollTo.js.map +2 -2
- package/utils/string/endsWith.cjs +35 -0
- package/utils/string/endsWith.cjs.map +7 -0
- package/utils/string/endsWith.d.ts +8 -0
- package/utils/string/endsWith.js +13 -0
- package/utils/string/endsWith.js.map +7 -0
- package/utils/string/index.cjs +7 -0
- package/utils/string/index.cjs.map +2 -2
- package/utils/string/index.d.ts +2 -0
- package/utils/string/index.js +2 -0
- package/utils/string/index.js.map +2 -2
- package/utils/string/startsWith.cjs +35 -0
- package/utils/string/startsWith.cjs.map +7 -0
- package/utils/string/startsWith.d.ts +8 -0
- package/utils/string/startsWith.js +13 -0
- package/utils/string/startsWith.js.map +7 -0
- package/utils/string/withLeadingCharacters.cjs +4 -0
- package/utils/string/withLeadingCharacters.cjs.map +1 -1
- package/utils/string/withLeadingCharacters.js.map +1 -1
- package/utils/string/withLeadingSlash.cjs +4 -0
- package/utils/string/withLeadingSlash.cjs.map +1 -1
- package/utils/string/withTrailingCharacters.cjs +4 -0
- package/utils/string/withTrailingCharacters.cjs.map +1 -1
- package/utils/string/withTrailingCharacters.js.map +1 -1
- package/utils/string/withTrailingSlash.cjs +4 -0
- package/utils/string/withTrailingSlash.cjs.map +1 -1
- package/utils/string/withoutLeadingCharacters.cjs.map +1 -1
- package/utils/string/withoutLeadingCharacters.js.map +1 -1
- package/utils/string/withoutLeadingCharactersRecursive.cjs +4 -0
- package/utils/string/withoutLeadingCharactersRecursive.cjs.map +1 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +1 -1
- package/utils/string/withoutLeadingSlash.cjs +4 -0
- package/utils/string/withoutLeadingSlash.cjs.map +1 -1
- package/utils/string/withoutTrailingCharacters.cjs.map +1 -1
- package/utils/string/withoutTrailingCharacters.js.map +1 -1
- package/utils/string/withoutTrailingCharactersRecursive.cjs +4 -0
- package/utils/string/withoutTrailingCharactersRecursive.cjs.map +1 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +1 -1
- package/utils/string/withoutTrailingSlash.cjs +4 -0
- package/utils/string/withoutTrailingSlash.cjs.map +1 -1
- package/utils/tween.cjs +4 -0
- package/utils/tween.cjs.map +1 -1
- package/utils/tween.js.map +1 -1
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -35,6 +39,9 @@ function withExtraConfig(BaseClass, config, options = {}) {
|
|
|
35
39
|
newConfig.name = `${BaseClass.config.name}WithExtraConfig`;
|
|
36
40
|
}
|
|
37
41
|
class WithExtraConfig extends BaseClass {
|
|
42
|
+
/**
|
|
43
|
+
* Config.
|
|
44
|
+
*/
|
|
38
45
|
static config = newConfig;
|
|
39
46
|
}
|
|
40
47
|
return WithExtraConfig;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withExtraConfig.ts"],
|
|
4
4
|
"sourcesContent": ["import merge from 'deepmerge';\nimport type { Options as DeepmergeOptions } from 'deepmerge';\nimport type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\n/**\n * Extends the configuration of an existing class.\n */\nexport function withExtraConfig<S extends Base>(\n BaseClass: typeof Base,\n config: Partial<BaseConfig>,\n options: DeepmergeOptions = {},\n): BaseDecorator<BaseInterface, S> {\n const newConfig = merge(BaseClass.config, config, options);\n\n if (newConfig.name === BaseClass.config.name) {\n newConfig.name = `${BaseClass.config.name}WithExtraConfig`;\n }\n\n /**\n * Class.\n */\n class WithExtraConfig<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Config.\n */\n static config: BaseConfig = newConfig;\n }\n\n // @ts-ignore\n return WithExtraConfig;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAkB;AAQX,SAAS,gBACd,WACA,QACA,UAA4B,CAAC,GACI;AACjC,QAAM,gBAAY,iBAAAA,SAAM,UAAU,QAAQ,QAAQ,OAAO;AAEzD,MAAI,UAAU,SAAS,UAAU,OAAO,MAAM;AAC5C,cAAU,OAAO,GAAG,UAAU,OAAO,IAAI;AAAA,EAC3C;AAAA,EAKA,MAAM,wBAAyD,UAAa;AAAA;AAAA;AAAA;AAAA,IAI1E,OAAO,SAAqB;AAAA,EAC9B;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": ["merge"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withExtraConfig.ts"],
|
|
4
4
|
"sourcesContent": ["import merge from 'deepmerge';\nimport type { Options as DeepmergeOptions } from 'deepmerge';\nimport type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\n/**\n * Extends the configuration of an existing class.\n */\nexport function withExtraConfig<S extends Base>(\n BaseClass: typeof Base,\n config: Partial<BaseConfig>,\n options: DeepmergeOptions = {},\n): BaseDecorator<BaseInterface, S> {\n const newConfig = merge(BaseClass.config, config, options);\n\n if (newConfig.name === BaseClass.config.name) {\n newConfig.name = `${BaseClass.config.name}WithExtraConfig`;\n }\n\n /**\n * Class.\n */\n class WithExtraConfig<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Config.\n */\n static config: BaseConfig = newConfig;\n }\n\n // @ts-ignore\n return WithExtraConfig;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,WAAW;AAQX,SAAS,gBACd,WACA,QACA,UAA4B,CAAC,GACI;AACjC,QAAM,YAAY,MAAM,UAAU,QAAQ,QAAQ,OAAO;AAEzD,MAAI,UAAU,SAAS,UAAU,OAAO,MAAM;AAC5C,cAAU,OAAO,GAAG,UAAU,OAAO;AAAA,
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAQX,SAAS,gBACd,WACA,QACA,UAA4B,CAAC,GACI;AACjC,QAAM,YAAY,MAAM,UAAU,QAAQ,QAAQ,OAAO;AAEzD,MAAI,UAAU,SAAS,UAAU,OAAO,MAAM;AAC5C,cAAU,OAAO,GAAG,UAAU,OAAO,IAAI;AAAA,EAC3C;AAAA,EAKA,MAAM,wBAAyD,UAAa;AAAA;AAAA;AAAA;AAAA,IAI1E,OAAO,SAAqB;AAAA,EAC9B;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,7 +24,15 @@ __export(withFreezedOptions_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(withFreezedOptions_exports);
|
|
25
25
|
function withFreezedOptions(BaseClass) {
|
|
26
26
|
class WithFreezedOptions extends BaseClass {
|
|
27
|
+
/**
|
|
28
|
+
* Hold freezed options
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
27
32
|
__freezedOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Lazyly freeze the `$options` property.
|
|
35
|
+
*/
|
|
28
36
|
get $options() {
|
|
29
37
|
if (!this.__freezedOptions) {
|
|
30
38
|
Object.defineProperty(this, "__freezedOptions", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withFreezedOptions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseOptions } from '../Base/index.js';\n\nexport interface WithFreezedOptionsInterface extends BaseInterface {\n readonly $options: Readonly<BaseOptions>;\n}\n\n/**\n * Freeze the `$options` property to improve performance.\n */\nexport function withFreezedOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithFreezedOptionsInterface, S> {\n /**\n * Class.\n */\n class WithFreezedOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Hold freezed options\n * @private\n */\n __freezedOptions;\n\n /**\n * Lazyly freeze the `$options` property.\n */\n get $options() {\n if (!this.__freezedOptions) {\n Object.defineProperty(this, '__freezedOptions', {\n value: Object.freeze({ ...super.$options }),\n enumerable: false,\n configurable: true,\n });\n }\n\n return this.__freezedOptions;\n }\n }\n\n // @ts-ignore\n return WithFreezedOptions;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,mBACd,WAC+C;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseOptions } from '../Base/index.js';\n\nexport interface WithFreezedOptionsInterface extends BaseInterface {\n readonly $options: Readonly<BaseOptions>;\n}\n\n/**\n * Freeze the `$options` property to improve performance.\n */\nexport function withFreezedOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithFreezedOptionsInterface, S> {\n /**\n * Class.\n */\n class WithFreezedOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Hold freezed options\n *\n * @private\n */\n __freezedOptions;\n\n /**\n * Lazyly freeze the `$options` property.\n */\n get $options() {\n if (!this.__freezedOptions) {\n Object.defineProperty(this, '__freezedOptions', {\n value: Object.freeze({ ...super.$options }),\n enumerable: false,\n configurable: true,\n });\n }\n\n return this.__freezedOptions;\n }\n }\n\n // @ts-ignore\n return WithFreezedOptions;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,mBACd,WAC+C;AAAA,EAI/C,MAAM,2BAA4D,UAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAM7E;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,WAAW;AACb,UAAI,CAAC,KAAK,kBAAkB;AAC1B,eAAO,eAAe,MAAM,oBAAoB;AAAA,UAC9C,OAAO,OAAO,OAAO,EAAE,GAAG,MAAM,SAAS,CAAC;AAAA,UAC1C,YAAY;AAAA,UACZ,cAAc;AAAA,QAChB,CAAC;AAAA,MACH;AAEA,aAAO,KAAK;AAAA,IACd;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
function withFreezedOptions(BaseClass) {
|
|
2
2
|
class WithFreezedOptions extends BaseClass {
|
|
3
|
+
/**
|
|
4
|
+
* Hold freezed options
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
3
8
|
__freezedOptions;
|
|
9
|
+
/**
|
|
10
|
+
* Lazyly freeze the `$options` property.
|
|
11
|
+
*/
|
|
4
12
|
get $options() {
|
|
5
13
|
if (!this.__freezedOptions) {
|
|
6
14
|
Object.defineProperty(this, "__freezedOptions", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withFreezedOptions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseOptions } from '../Base/index.js';\n\nexport interface WithFreezedOptionsInterface extends BaseInterface {\n readonly $options: Readonly<BaseOptions>;\n}\n\n/**\n * Freeze the `$options` property to improve performance.\n */\nexport function withFreezedOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithFreezedOptionsInterface, S> {\n /**\n * Class.\n */\n class WithFreezedOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Hold freezed options\n * @private\n */\n __freezedOptions;\n\n /**\n * Lazyly freeze the `$options` property.\n */\n get $options() {\n if (!this.__freezedOptions) {\n Object.defineProperty(this, '__freezedOptions', {\n value: Object.freeze({ ...super.$options }),\n enumerable: false,\n configurable: true,\n });\n }\n\n return this.__freezedOptions;\n }\n }\n\n // @ts-ignore\n return WithFreezedOptions;\n}\n"],
|
|
5
|
-
"mappings": "AAUO,SAAS,mBACd,WAC+C;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseOptions } from '../Base/index.js';\n\nexport interface WithFreezedOptionsInterface extends BaseInterface {\n readonly $options: Readonly<BaseOptions>;\n}\n\n/**\n * Freeze the `$options` property to improve performance.\n */\nexport function withFreezedOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithFreezedOptionsInterface, S> {\n /**\n * Class.\n */\n class WithFreezedOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Hold freezed options\n *\n * @private\n */\n __freezedOptions;\n\n /**\n * Lazyly freeze the `$options` property.\n */\n get $options() {\n if (!this.__freezedOptions) {\n Object.defineProperty(this, '__freezedOptions', {\n value: Object.freeze({ ...super.$options }),\n enumerable: false,\n configurable: true,\n });\n }\n\n return this.__freezedOptions;\n }\n }\n\n // @ts-ignore\n return WithFreezedOptions;\n}\n"],
|
|
5
|
+
"mappings": "AAUO,SAAS,mBACd,WAC+C;AAAA,EAI/C,MAAM,2BAA4D,UAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAM7E;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,WAAW;AACb,UAAI,CAAC,KAAK,kBAAkB;AAC1B,eAAO,eAAe,MAAM,oBAAoB;AAAA,UAC9C,OAAO,OAAO,OAAO,EAAE,GAAG,MAAM,SAAS,CAAC;AAAA,UAC1C,YAAY;AAAA,UACZ,cAAc;AAAA,QAChB,CAAC;AAAA,MACH;AAEA,aAAO,KAAK;AAAA,IACd;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,10 +23,13 @@ __export(withIntersectionObserver_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(withIntersectionObserver_exports);
|
|
25
25
|
function createArrayOfNumber(length) {
|
|
26
|
-
return
|
|
26
|
+
return new Array(length + 1).fill(length).map((val, index) => index / length);
|
|
27
27
|
}
|
|
28
28
|
function withIntersectionObserver(BaseClass, defaultOptions = { threshold: createArrayOfNumber(100) }) {
|
|
29
29
|
class WithIntersectionObserver extends BaseClass {
|
|
30
|
+
/**
|
|
31
|
+
* Config
|
|
32
|
+
*/
|
|
30
33
|
static config = {
|
|
31
34
|
...BaseClass.config,
|
|
32
35
|
name: `${BaseClass.config.name}WithIntersectionObserver`,
|
|
@@ -36,7 +39,13 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
|
|
|
36
39
|
},
|
|
37
40
|
emits: ["intersected"]
|
|
38
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Intersection observer instance.
|
|
44
|
+
*/
|
|
39
45
|
$observer;
|
|
46
|
+
/**
|
|
47
|
+
* Create an observer when the class in instantiated.
|
|
48
|
+
*/
|
|
40
49
|
constructor(element) {
|
|
41
50
|
super(element);
|
|
42
51
|
this.$observer = new IntersectionObserver(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withIntersectionObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithIntersectionObserverProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n $observer: IntersectionObserver;\n intersected(entries: IntersectionObserverEntry[]): void;\n}\n\nexport interface WithIntersectionObserverInterface extends BaseInterface {\n $observer: IntersectionObserver;\n}\n\n/**\n * Create an array of number between 0 and 1 from the given length.\n */\nfunction createArrayOfNumber(length: number): number[] {\n return
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,SAAS,oBAAoB,QAA0B;AACrD,SAAO,
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithIntersectionObserverProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n $observer: IntersectionObserver;\n intersected(entries: IntersectionObserverEntry[]): void;\n}\n\nexport interface WithIntersectionObserverInterface extends BaseInterface {\n $observer: IntersectionObserver;\n}\n\n/**\n * Create an array of number between 0 and 1 from the given length.\n */\nfunction createArrayOfNumber(length: number): number[] {\n return new Array(length + 1).fill(length).map((val, index) => index / length);\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withIntersectionObserver<S extends Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: createArrayOfNumber(100) },\n): BaseDecorator<WithIntersectionObserverInterface, S, WithIntersectionObserverProps> {\n /**\n * Class.\n */\n class WithIntersectionObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithIntersectionObserverProps\n > {\n /**\n * Config\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithIntersectionObserver`,\n options: {\n ...(BaseClass.config?.options || {}),\n intersectionObserver: Object,\n },\n emits: ['intersected'],\n };\n\n /**\n * Intersection observer instance.\n */\n $observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$observer = new IntersectionObserver(\n (entries) => {\n this.__callMethod('intersected', entries);\n },\n {\n ...defaultOptions,\n ...(this.$options.intersectionObserver as IntersectionObserverInit),\n },\n );\n\n this.$on('mounted', () => {\n this.$observer.observe(this.$el);\n });\n\n this.$on('destroyed', () => {\n this.$observer.unobserve(this.$el);\n });\n }\n }\n\n // @ts-ignore\n return WithIntersectionObserver;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,SAAS,oBAAoB,QAA0B;AACrD,SAAO,IAAI,MAAM,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,IAAI,CAAC,KAAK,UAAU,QAAQ,MAAM;AAC9E;AAKO,SAAS,yBACd,WAEA,iBAA2C,EAAE,WAAW,oBAAoB,GAAG,EAAE,GACG;AAAA,EAIpF,MAAM,iCAAkE,UAEtE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,sBAAsB;AAAA,MACxB;AAAA,MACA,OAAO,CAAC,aAAa;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,YAAY,IAAI;AAAA,QACnB,CAAC,YAAY;AACX,eAAK,aAAa,eAAe,OAAO;AAAA,QAC1C;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SAAS;AAAA,QACpB;AAAA,MACF;AAEA,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU,QAAQ,KAAK,GAAG;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,UAAU,KAAK,GAAG;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
function createArrayOfNumber(length) {
|
|
2
|
-
return
|
|
2
|
+
return new Array(length + 1).fill(length).map((val, index) => index / length);
|
|
3
3
|
}
|
|
4
4
|
function withIntersectionObserver(BaseClass, defaultOptions = { threshold: createArrayOfNumber(100) }) {
|
|
5
5
|
class WithIntersectionObserver extends BaseClass {
|
|
6
|
+
/**
|
|
7
|
+
* Config
|
|
8
|
+
*/
|
|
6
9
|
static config = {
|
|
7
10
|
...BaseClass.config,
|
|
8
11
|
name: `${BaseClass.config.name}WithIntersectionObserver`,
|
|
@@ -12,7 +15,13 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
|
|
|
12
15
|
},
|
|
13
16
|
emits: ["intersected"]
|
|
14
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Intersection observer instance.
|
|
20
|
+
*/
|
|
15
21
|
$observer;
|
|
22
|
+
/**
|
|
23
|
+
* Create an observer when the class in instantiated.
|
|
24
|
+
*/
|
|
16
25
|
constructor(element) {
|
|
17
26
|
super(element);
|
|
18
27
|
this.$observer = new IntersectionObserver(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withIntersectionObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithIntersectionObserverProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n $observer: IntersectionObserver;\n intersected(entries: IntersectionObserverEntry[]): void;\n}\n\nexport interface WithIntersectionObserverInterface extends BaseInterface {\n $observer: IntersectionObserver;\n}\n\n/**\n * Create an array of number between 0 and 1 from the given length.\n */\nfunction createArrayOfNumber(length: number): number[] {\n return
|
|
5
|
-
"mappings": "AAkBA,SAAS,oBAAoB,QAA0B;AACrD,SAAO,
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithIntersectionObserverProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n $observer: IntersectionObserver;\n intersected(entries: IntersectionObserverEntry[]): void;\n}\n\nexport interface WithIntersectionObserverInterface extends BaseInterface {\n $observer: IntersectionObserver;\n}\n\n/**\n * Create an array of number between 0 and 1 from the given length.\n */\nfunction createArrayOfNumber(length: number): number[] {\n return new Array(length + 1).fill(length).map((val, index) => index / length);\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withIntersectionObserver<S extends Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: createArrayOfNumber(100) },\n): BaseDecorator<WithIntersectionObserverInterface, S, WithIntersectionObserverProps> {\n /**\n * Class.\n */\n class WithIntersectionObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithIntersectionObserverProps\n > {\n /**\n * Config\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithIntersectionObserver`,\n options: {\n ...(BaseClass.config?.options || {}),\n intersectionObserver: Object,\n },\n emits: ['intersected'],\n };\n\n /**\n * Intersection observer instance.\n */\n $observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$observer = new IntersectionObserver(\n (entries) => {\n this.__callMethod('intersected', entries);\n },\n {\n ...defaultOptions,\n ...(this.$options.intersectionObserver as IntersectionObserverInit),\n },\n );\n\n this.$on('mounted', () => {\n this.$observer.observe(this.$el);\n });\n\n this.$on('destroyed', () => {\n this.$observer.unobserve(this.$el);\n });\n }\n }\n\n // @ts-ignore\n return WithIntersectionObserver;\n}\n"],
|
|
5
|
+
"mappings": "AAkBA,SAAS,oBAAoB,QAA0B;AACrD,SAAO,IAAI,MAAM,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,IAAI,CAAC,KAAK,UAAU,QAAQ,MAAM;AAC9E;AAKO,SAAS,yBACd,WAEA,iBAA2C,EAAE,WAAW,oBAAoB,GAAG,EAAE,GACG;AAAA,EAIpF,MAAM,iCAAkE,UAEtE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,sBAAsB;AAAA,MACxB;AAAA,MACA,OAAO,CAAC,aAAa;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,YAAY,IAAI;AAAA,QACnB,CAAC,YAAY;AACX,eAAK,aAAa,eAAe,OAAO;AAAA,QAC1C;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SAAS;AAAA,QACpB;AAAA,MACF;AAEA,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU,QAAQ,KAAK,GAAG;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,UAAU,KAAK,GAAG;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -25,6 +25,9 @@ module.exports = __toCommonJS(withMountOnMediaQuery_exports);
|
|
|
25
25
|
var import_is = require("../utils/is.cjs");
|
|
26
26
|
function withMountOnMediaQuery(BaseClass, media) {
|
|
27
27
|
class WithMountOnMediaQuery extends BaseClass {
|
|
28
|
+
/**
|
|
29
|
+
* Config.
|
|
30
|
+
*/
|
|
28
31
|
static config = {
|
|
29
32
|
...BaseClass.config,
|
|
30
33
|
name: `${BaseClass.config.name}withMountOnMediaQuery`,
|
|
@@ -33,7 +36,17 @@ function withMountOnMediaQuery(BaseClass, media) {
|
|
|
33
36
|
media: String
|
|
34
37
|
}
|
|
35
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Is the media query matches?
|
|
41
|
+
*
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
36
44
|
__matches = false;
|
|
45
|
+
/**
|
|
46
|
+
* Listen for media query changes when the class in instantiated.
|
|
47
|
+
*
|
|
48
|
+
* @param {HTMLElement} element The component's root element.
|
|
49
|
+
*/
|
|
37
50
|
constructor(element) {
|
|
38
51
|
super(element);
|
|
39
52
|
if (import_is.isDev && !this.$options.media && !media) {
|
|
@@ -57,6 +70,9 @@ function withMountOnMediaQuery(BaseClass, media) {
|
|
|
57
70
|
mediaQueryList.removeEventListener("change", changeHandler);
|
|
58
71
|
});
|
|
59
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Override the mounting of the component.
|
|
75
|
+
*/
|
|
60
76
|
$mount() {
|
|
61
77
|
if (this.__matches) {
|
|
62
78
|
super.$mount();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountOnMediaQuery.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}withMountOnMediaQuery`,\n options: {\n ...(BaseClass.config?.options || {}),\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes 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 if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__matches) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gBAAsB;AAmBf,SAAS,sBACd,WACA,OAC8E;
|
|
4
|
+
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}withMountOnMediaQuery`,\n options: {\n ...(BaseClass.config?.options || {}),\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n *\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes 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 if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__matches) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gBAAsB;AAmBf,SAAS,sBACd,WACA,OAC8E;AAAA,EAI9E,MAAM,8BAA+D,UAEnE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,OAAO;AAAA,MACT;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOZ,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,UAAI,mBAAS,CAAC,KAAK,SAAS,SAAS,CAAC,OAAO;AAC3C,aAAK;AAAA,UACH;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,iBAAiB,OAAO,WAAW,KAAK,SAAS,SAAS,KAAK;AAGrE,WAAK,YAAY,eAAe;AAEhC,YAAM,gBAAgB,CAAC,UAA+B;AACpD,aAAK,YAAY,MAAM;AAEvB,YAAI,MAAM,WAAW,CAAC,KAAK,YAAY;AACrC,eAAK,OAAO;AAAA,QACd,WAAW,KAAK,YAAY;AAC1B,qBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,QAClC;AAAA,MACF;AAGA,qBAAe,iBAAiB,UAAU,aAAa;AAEvD,WAAK,IAAI,cAAc,MAAM;AAC3B,uBAAe,oBAAoB,UAAU,aAAa;AAAA,MAC5D,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;AACP,UAAI,KAAK,WAAW;AAClB,cAAM,OAAO;AAAA,MACf;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isDev } from "../utils/is.js";
|
|
2
2
|
function withMountOnMediaQuery(BaseClass, media) {
|
|
3
3
|
class WithMountOnMediaQuery extends BaseClass {
|
|
4
|
+
/**
|
|
5
|
+
* Config.
|
|
6
|
+
*/
|
|
4
7
|
static config = {
|
|
5
8
|
...BaseClass.config,
|
|
6
9
|
name: `${BaseClass.config.name}withMountOnMediaQuery`,
|
|
@@ -9,7 +12,17 @@ function withMountOnMediaQuery(BaseClass, media) {
|
|
|
9
12
|
media: String
|
|
10
13
|
}
|
|
11
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Is the media query matches?
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
12
20
|
__matches = false;
|
|
21
|
+
/**
|
|
22
|
+
* Listen for media query changes when the class in instantiated.
|
|
23
|
+
*
|
|
24
|
+
* @param {HTMLElement} element The component's root element.
|
|
25
|
+
*/
|
|
13
26
|
constructor(element) {
|
|
14
27
|
super(element);
|
|
15
28
|
if (isDev && !this.$options.media && !media) {
|
|
@@ -33,6 +46,9 @@ function withMountOnMediaQuery(BaseClass, media) {
|
|
|
33
46
|
mediaQueryList.removeEventListener("change", changeHandler);
|
|
34
47
|
});
|
|
35
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Override the mounting of the component.
|
|
51
|
+
*/
|
|
36
52
|
$mount() {
|
|
37
53
|
if (this.__matches) {
|
|
38
54
|
super.$mount();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountOnMediaQuery.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}withMountOnMediaQuery`,\n options: {\n ...(BaseClass.config?.options || {}),\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes 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 if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__matches) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,aAAa;AAmBf,SAAS,sBACd,WACA,OAC8E;
|
|
4
|
+
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}withMountOnMediaQuery`,\n options: {\n ...(BaseClass.config?.options || {}),\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n *\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes 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 if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n $mount() {\n if (this.__matches) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,aAAa;AAmBf,SAAS,sBACd,WACA,OAC8E;AAAA,EAI9E,MAAM,8BAA+D,UAEnE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,OAAO;AAAA,MACT;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOZ,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,UAAI,SAAS,CAAC,KAAK,SAAS,SAAS,CAAC,OAAO;AAC3C,aAAK;AAAA,UACH;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,iBAAiB,OAAO,WAAW,KAAK,SAAS,SAAS,KAAK;AAGrE,WAAK,YAAY,eAAe;AAEhC,YAAM,gBAAgB,CAAC,UAA+B;AACpD,aAAK,YAAY,MAAM;AAEvB,YAAI,MAAM,WAAW,CAAC,KAAK,YAAY;AACrC,eAAK,OAAO;AAAA,QACd,WAAW,KAAK,YAAY;AAC1B,qBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,QAClC;AAAA,MACF;AAGA,qBAAe,iBAAiB,UAAU,aAAa;AAEvD,WAAK,IAAI,cAAc,MAAM;AAC3B,uBAAe,oBAAoB,UAAU,aAAa;AAAA,MAC5D,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;AACP,UAAI,KAAK,WAAW;AAClB,cAAM,OAAO;AAAA,MACf;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,6 +24,9 @@ __export(withMountWhenInView_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(withMountWhenInView_exports);
|
|
25
25
|
function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
|
|
26
26
|
class WithMountWhenInView extends BaseClass {
|
|
27
|
+
/**
|
|
28
|
+
* Config.
|
|
29
|
+
*/
|
|
27
30
|
static config = {
|
|
28
31
|
...BaseClass.config,
|
|
29
32
|
name: `${BaseClass.config.name}WithMountWhenInView`,
|
|
@@ -32,8 +35,23 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
32
35
|
intersectionObserver: Object
|
|
33
36
|
}
|
|
34
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Is the component visible?
|
|
40
|
+
*
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
35
43
|
__isVisible = false;
|
|
44
|
+
/**
|
|
45
|
+
* The component's observer.
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
36
49
|
__observer;
|
|
50
|
+
/**
|
|
51
|
+
* Create an observer when the class in instantiated.
|
|
52
|
+
*
|
|
53
|
+
* @param {HTMLElement} element The component's root element.
|
|
54
|
+
*/
|
|
37
55
|
constructor(element) {
|
|
38
56
|
super(element);
|
|
39
57
|
this.__observer = new IntersectionObserver(
|
|
@@ -58,6 +76,9 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
58
76
|
this.__observer.disconnect();
|
|
59
77
|
});
|
|
60
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Override the mounting of the component.
|
|
81
|
+
*/
|
|
61
82
|
$mount() {
|
|
62
83
|
if (this.__isVisible) {
|
|
63
84
|
super.$mount();
|
|
@@ -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 name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...(BaseClass.config?.options || {}),\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\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 $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;
|
|
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 name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...(BaseClass.config?.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 $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,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,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,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,SAAS;AACP,UAAI,KAAK,aAAa;AACpB,cAAM,OAAO;AAAA,MACf;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
|
|
2
2
|
class WithMountWhenInView extends BaseClass {
|
|
3
|
+
/**
|
|
4
|
+
* Config.
|
|
5
|
+
*/
|
|
3
6
|
static config = {
|
|
4
7
|
...BaseClass.config,
|
|
5
8
|
name: `${BaseClass.config.name}WithMountWhenInView`,
|
|
@@ -8,8 +11,23 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
8
11
|
intersectionObserver: Object
|
|
9
12
|
}
|
|
10
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Is the component visible?
|
|
16
|
+
*
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
11
19
|
__isVisible = false;
|
|
20
|
+
/**
|
|
21
|
+
* The component's observer.
|
|
22
|
+
*
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
12
25
|
__observer;
|
|
26
|
+
/**
|
|
27
|
+
* Create an observer when the class in instantiated.
|
|
28
|
+
*
|
|
29
|
+
* @param {HTMLElement} element The component's root element.
|
|
30
|
+
*/
|
|
13
31
|
constructor(element) {
|
|
14
32
|
super(element);
|
|
15
33
|
this.__observer = new IntersectionObserver(
|
|
@@ -34,6 +52,9 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
34
52
|
this.__observer.disconnect();
|
|
35
53
|
});
|
|
36
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Override the mounting of the component.
|
|
57
|
+
*/
|
|
37
58
|
$mount() {
|
|
38
59
|
if (this.__isVisible) {
|
|
39
60
|
super.$mount();
|
|
@@ -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 name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...(BaseClass.config?.options || {}),\n intersectionObserver: Object,\n },\n };\n\n /**\n * Is the component visible?\n * @private\n */\n __isVisible = false;\n\n /**\n * The component's observer.\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 $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
-
"mappings": "AAwBO,SAAS,oBACd,WAEA,iBAA2C,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,GACW;
|
|
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 name: `${BaseClass.config.name}WithMountWhenInView`,\n options: {\n ...(BaseClass.config?.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 $mount() {\n if (this.__isVisible) {\n super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountWhenInView;\n}\n"],
|
|
5
|
+
"mappings": "AAwBO,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,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP,GAAI,UAAU,QAAQ,WAAW,CAAC;AAAA,QAClC,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,SAAS;AACP,UAAI,KAAK,aAAa;AACpB,cAAM,OAAO;AAAA,MACf;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/decorators/withRelativePointer.ts
|
|
20
|
+
var withRelativePointer_exports = {};
|
|
21
|
+
__export(withRelativePointer_exports, {
|
|
22
|
+
withRelativePointer: () => withRelativePointer
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(withRelativePointer_exports);
|
|
25
|
+
var import_services = require("../services/index.cjs");
|
|
26
|
+
function withRelativePointer(BaseClass, { target = (instance) => instance.$el } = {}) {
|
|
27
|
+
class WithRelativePointer extends BaseClass {
|
|
28
|
+
/**
|
|
29
|
+
* Config.
|
|
30
|
+
*/
|
|
31
|
+
static config = {
|
|
32
|
+
name: `${BaseClass.config.name}WithRelativePointer`,
|
|
33
|
+
emits: ["movedrelative"]
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Class constructor.
|
|
37
|
+
*/
|
|
38
|
+
constructor(element) {
|
|
39
|
+
super(element);
|
|
40
|
+
this.$on("mounted", () => {
|
|
41
|
+
this.$services.register(
|
|
42
|
+
"movedrelative",
|
|
43
|
+
import_services.usePointer.bind(void 0, target.call(this, this))
|
|
44
|
+
);
|
|
45
|
+
this.$services.enable("movedrelative");
|
|
46
|
+
});
|
|
47
|
+
this.$on("destroyed", () => {
|
|
48
|
+
this.$services.disable("movedrelative");
|
|
49
|
+
this.$services.unregister("movedrelative");
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return WithRelativePointer;
|
|
54
|
+
}
|
|
55
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
56
|
+
//# sourceMappingURL=withRelativePointer.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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/pointer.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 name: `${BaseClass.config.name}WithRelativePointer`,\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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA2B;AAapB,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,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,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,2BAAW,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BaseDecorator, BaseInterface } from '../Base/types.js';
|
|
2
|
+
import type { Base } from '../Base/index.js';
|
|
3
|
+
import type { PointerServiceProps } from '../services/pointer.js';
|
|
4
|
+
export type RelativePointerDecoratorOptions = {
|
|
5
|
+
target?: (this: Base, instance: Base) => HTMLElement;
|
|
6
|
+
};
|
|
7
|
+
export interface RelativePointerInterface extends BaseInterface {
|
|
8
|
+
movedrelative?(props: PointerServiceProps): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Add dragging capabilities to a component.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withRelativePointer<S extends Base>(BaseClass: typeof Base, { target }?: RelativePointerDecoratorOptions): BaseDecorator<RelativePointerInterface, S>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { usePointer } from "../services/index.js";
|
|
2
|
+
function withRelativePointer(BaseClass, { target = (instance) => instance.$el } = {}) {
|
|
3
|
+
class WithRelativePointer extends BaseClass {
|
|
4
|
+
/**
|
|
5
|
+
* Config.
|
|
6
|
+
*/
|
|
7
|
+
static config = {
|
|
8
|
+
name: `${BaseClass.config.name}WithRelativePointer`,
|
|
9
|
+
emits: ["movedrelative"]
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Class constructor.
|
|
13
|
+
*/
|
|
14
|
+
constructor(element) {
|
|
15
|
+
super(element);
|
|
16
|
+
this.$on("mounted", () => {
|
|
17
|
+
this.$services.register(
|
|
18
|
+
"movedrelative",
|
|
19
|
+
usePointer.bind(void 0, target.call(this, this))
|
|
20
|
+
);
|
|
21
|
+
this.$services.enable("movedrelative");
|
|
22
|
+
});
|
|
23
|
+
this.$on("destroyed", () => {
|
|
24
|
+
this.$services.disable("movedrelative");
|
|
25
|
+
this.$services.unregister("movedrelative");
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return WithRelativePointer;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
withRelativePointer
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=withRelativePointer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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/pointer.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 name: `${BaseClass.config.name}WithRelativePointer`,\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;AAapB,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,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,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
|
+
"names": []
|
|
7
|
+
}
|