@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
|
@@ -25,6 +25,9 @@ module.exports = __toCommonJS(withResponsiveOptions_exports);
|
|
|
25
25
|
var import_ResponsiveOptionsManager = require("../Base/managers/ResponsiveOptionsManager.cjs");
|
|
26
26
|
function withResponsiveOptions(BaseClass) {
|
|
27
27
|
class WithResponsiveOptions extends BaseClass {
|
|
28
|
+
/**
|
|
29
|
+
* Get managers.
|
|
30
|
+
*/
|
|
28
31
|
get __managers() {
|
|
29
32
|
return {
|
|
30
33
|
...super.__managers,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withResponsiveOptions.ts"],
|
|
4
4
|
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, Managers } from '../Base/index.js';\nimport { ResponsiveOptionsManager } from '../Base/managers/ResponsiveOptionsManager.js';\n\n/**\n * Extends the configuration of an existing class.\n */\nexport function withResponsiveOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithResponsiveOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sCAAyC;AAKlC,SAAS,sBACd,WACiC;
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sCAAyC;AAKlC,SAAS,sBACd,WACiC;AAAA,EAIjC,MAAM,8BAA+D,UAAa;AAAA;AAAA;AAAA;AAAA,IAIhF,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
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ResponsiveOptionsManager } from "../Base/managers/ResponsiveOptionsManager.js";
|
|
2
2
|
function withResponsiveOptions(BaseClass) {
|
|
3
3
|
class WithResponsiveOptions extends BaseClass {
|
|
4
|
+
/**
|
|
5
|
+
* Get managers.
|
|
6
|
+
*/
|
|
4
7
|
get __managers() {
|
|
5
8
|
return {
|
|
6
9
|
...super.__managers,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withResponsiveOptions.ts"],
|
|
4
4
|
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, Managers } from '../Base/index.js';\nimport { ResponsiveOptionsManager } from '../Base/managers/ResponsiveOptionsManager.js';\n\n/**\n * Extends the configuration of an existing class.\n */\nexport function withResponsiveOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithResponsiveOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\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": "AAEA,SAAS,gCAAgC;AAKlC,SAAS,sBACd,WACiC;
|
|
5
|
+
"mappings": "AAEA,SAAS,gCAAgC;AAKlC,SAAS,sBACd,WACiC;AAAA,EAIjC,MAAM,8BAA+D,UAAa;AAAA;AAAA;AAAA;AAAA,IAIhF,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,7 +52,7 @@ function parseNamedOffset(offset) {
|
|
|
52
52
|
if ((0, import_utils.isNumber)(Number(offset))) {
|
|
53
53
|
return Number(offset);
|
|
54
54
|
}
|
|
55
|
-
if ((0, import_utils.isString)(offset) &&
|
|
55
|
+
if ((0, import_utils.isString)(offset) && (0, import_utils.endsWith)(offset, units.percent)) {
|
|
56
56
|
return Number.parseFloat(offset) / 100;
|
|
57
57
|
}
|
|
58
58
|
return offset;
|
|
@@ -67,19 +67,19 @@ function getEdgeWithOffset(start, size, offset) {
|
|
|
67
67
|
}
|
|
68
68
|
if ((0, import_utils.isString)(parsedNamedOffset)) {
|
|
69
69
|
const parsedOffset = Number.parseFloat(parsedNamedOffset);
|
|
70
|
-
if (
|
|
70
|
+
if ((0, import_utils.endsWith)(parsedNamedOffset, units.px)) {
|
|
71
71
|
return start + parsedOffset;
|
|
72
72
|
}
|
|
73
|
-
if (
|
|
73
|
+
if ((0, import_utils.endsWith)(parsedNamedOffset, units.vh)) {
|
|
74
74
|
return start + parsedOffset * window.innerHeight / 100;
|
|
75
75
|
}
|
|
76
|
-
if (
|
|
76
|
+
if ((0, import_utils.endsWith)(parsedNamedOffset, units.vw)) {
|
|
77
77
|
return start + parsedOffset * window.innerWidth / 100;
|
|
78
78
|
}
|
|
79
|
-
if (
|
|
79
|
+
if ((0, import_utils.endsWith)(parsedNamedOffset, units.vmin)) {
|
|
80
80
|
return start + parsedOffset * Math.min(window.innerWidth, window.innerHeight) / 100;
|
|
81
81
|
}
|
|
82
|
-
if (
|
|
82
|
+
if ((0, import_utils.endsWith)(parsedNamedOffset, units.vmax)) {
|
|
83
83
|
return start + parsedOffset * Math.max(window.innerWidth, window.innerHeight) / 100;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { isNumber, isString } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) &&
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { isNumber, isString, endsWith } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) && endsWith(offset, units.percent)) {\n return Number.parseFloat(offset) / 100;\n }\n\n return offset;\n}\n\n/**\n * Get an edge value given a start, size and offset value.\n */\nexport function getEdgeWithOffset(start: number, size: number, offset: string | number): number {\n if (isNumber(offset)) {\n return start + size * offset;\n }\n\n const parsedNamedOffset = parseNamedOffset(offset);\n if (isNumber(parsedNamedOffset)) {\n return start + size * parsedNamedOffset;\n }\n\n if (isString(parsedNamedOffset)) {\n const parsedOffset = Number.parseFloat(parsedNamedOffset);\n\n if (endsWith(parsedNamedOffset, units.px)) {\n return start + parsedOffset;\n }\n\n if (endsWith(parsedNamedOffset, units.vh)) {\n return start + (parsedOffset * window.innerHeight) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vw)) {\n return start + (parsedOffset * window.innerWidth) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmin)) {\n return start + (parsedOffset * Math.min(window.innerWidth, window.innerHeight)) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmax)) {\n return start + (parsedOffset * Math.max(window.innerWidth, window.innerHeight)) / 100;\n }\n }\n\n return start;\n}\n\n/**\n * Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.\n */\nexport function getEdges(axis: 'x' | 'y', targetSizes, containerSizes, offset): [number, number] {\n const sizeKey = axis === 'x' ? 'width' : 'height';\n const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);\n const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);\n const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);\n const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);\n const start = targetStart - containerStart;\n const end = targetEnd - containerEnd;\n\n return [start, end];\n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MAAM,EAAE,GAAG;AACzC,aAAO,QAAS,eAAe,OAAO,cAAe;AAAA,IACvD;AAEA,YAAI,uBAAS,mBAAmB,MAAM,EAAE,GAAG;AACzC,aAAO,QAAS,eAAe,OAAO,aAAc;AAAA,IACtD;AAEA,YAAI,uBAAS,mBAAmB,MAAM,IAAI,GAAG;AAC3C,aAAO,QAAS,eAAe,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,IACpF;AAEA,YAAI,uBAAS,mBAAmB,MAAM,IAAI,GAAG;AAC3C,aAAO,QAAS,eAAe,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,IACpF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,SAAS,SAAS,MAAiB,aAAa,gBAAgB,QAA0B;AAC/F,QAAM,UAAU,SAAS,MAAM,UAAU;AACzC,QAAM,cAAc,kBAAkB,YAAY,IAAI,GAAG,YAAY,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC3F,QAAM,iBAAiB,kBAAkB,GAAG,eAAe,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AACjF,QAAM,YAAY,kBAAkB,YAAY,IAAI,GAAG,YAAY,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AACzF,QAAM,eAAe,kBAAkB,GAAG,eAAe,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC/E,QAAM,QAAQ,cAAc;AAC5B,QAAM,MAAM,YAAY;AAExB,SAAO,CAAC,OAAO,GAAG;AACpB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNumber, isString } from "../../utils/index.js";
|
|
1
|
+
import { isNumber, isString, endsWith } from "../../utils/index.js";
|
|
2
2
|
const units = {
|
|
3
3
|
px: "px",
|
|
4
4
|
vh: "vh",
|
|
@@ -25,7 +25,7 @@ function parseNamedOffset(offset) {
|
|
|
25
25
|
if (isNumber(Number(offset))) {
|
|
26
26
|
return Number(offset);
|
|
27
27
|
}
|
|
28
|
-
if (isString(offset) &&
|
|
28
|
+
if (isString(offset) && endsWith(offset, units.percent)) {
|
|
29
29
|
return Number.parseFloat(offset) / 100;
|
|
30
30
|
}
|
|
31
31
|
return offset;
|
|
@@ -40,19 +40,19 @@ function getEdgeWithOffset(start, size, offset) {
|
|
|
40
40
|
}
|
|
41
41
|
if (isString(parsedNamedOffset)) {
|
|
42
42
|
const parsedOffset = Number.parseFloat(parsedNamedOffset);
|
|
43
|
-
if (
|
|
43
|
+
if (endsWith(parsedNamedOffset, units.px)) {
|
|
44
44
|
return start + parsedOffset;
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
46
|
+
if (endsWith(parsedNamedOffset, units.vh)) {
|
|
47
47
|
return start + parsedOffset * window.innerHeight / 100;
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
49
|
+
if (endsWith(parsedNamedOffset, units.vw)) {
|
|
50
50
|
return start + parsedOffset * window.innerWidth / 100;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
52
|
+
if (endsWith(parsedNamedOffset, units.vmin)) {
|
|
53
53
|
return start + parsedOffset * Math.min(window.innerWidth, window.innerHeight) / 100;
|
|
54
54
|
}
|
|
55
|
-
if (
|
|
55
|
+
if (endsWith(parsedNamedOffset, units.vmax)) {
|
|
56
56
|
return start + parsedOffset * Math.max(window.innerWidth, window.innerHeight) / 100;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { isNumber, isString } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) &&
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import { isNumber, isString, endsWith } from '../../utils/index.js';\nimport type { NormalizedOffset } from './types.js';\n\nconst units = {\n px: 'px',\n vh: 'vh',\n vw: 'vw',\n vmin: 'vmin',\n vmax: 'vmax',\n percent: '%',\n};\n\nconst namedOffsets = {\n start: 0,\n center: 0.5,\n end: 1,\n};\n\n/**\n * Normalize offset input.\n */\nexport function normalizeOffset(offsets: string): NormalizedOffset {\n return offsets\n .split('/')\n .map((offset) => offset.trim().split(' ').slice(0, 2)) as NormalizedOffset;\n}\n\n/**\n * Parse the given offset.\n */\nexport function parseNamedOffset(offset: string | number): string | number {\n if (isNumber(offset)) {\n return offset;\n }\n\n if (isNumber(namedOffsets[offset])) {\n return namedOffsets[offset];\n }\n\n if (isNumber(Number(offset))) {\n return Number(offset);\n }\n\n if (isString(offset) && endsWith(offset, units.percent)) {\n return Number.parseFloat(offset) / 100;\n }\n\n return offset;\n}\n\n/**\n * Get an edge value given a start, size and offset value.\n */\nexport function getEdgeWithOffset(start: number, size: number, offset: string | number): number {\n if (isNumber(offset)) {\n return start + size * offset;\n }\n\n const parsedNamedOffset = parseNamedOffset(offset);\n if (isNumber(parsedNamedOffset)) {\n return start + size * parsedNamedOffset;\n }\n\n if (isString(parsedNamedOffset)) {\n const parsedOffset = Number.parseFloat(parsedNamedOffset);\n\n if (endsWith(parsedNamedOffset, units.px)) {\n return start + parsedOffset;\n }\n\n if (endsWith(parsedNamedOffset, units.vh)) {\n return start + (parsedOffset * window.innerHeight) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vw)) {\n return start + (parsedOffset * window.innerWidth) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmin)) {\n return start + (parsedOffset * Math.min(window.innerWidth, window.innerHeight)) / 100;\n }\n\n if (endsWith(parsedNamedOffset, units.vmax)) {\n return start + (parsedOffset * Math.max(window.innerWidth, window.innerHeight)) / 100;\n }\n }\n\n return start;\n}\n\n/**\n * Get starting and ending edges for a given axis, a target sizings, a container sizings and their offset.\n */\nexport function getEdges(axis: 'x' | 'y', targetSizes, containerSizes, offset): [number, number] {\n const sizeKey = axis === 'x' ? 'width' : 'height';\n const targetStart = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[0][0]);\n const containerStart = getEdgeWithOffset(0, containerSizes[sizeKey], offset[0][1]);\n const targetEnd = getEdgeWithOffset(targetSizes[axis], targetSizes[sizeKey], offset[1][0]);\n const containerEnd = getEdgeWithOffset(0, containerSizes[sizeKey], offset[1][1]);\n const start = targetStart - containerStart;\n const end = targetEnd - containerEnd;\n\n return [start, end];\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,UAAU,gBAAgB;AAG7C,MAAM,QAAQ;AAAA,EACZ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AACX;AAEA,MAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AACP;AAKO,SAAS,gBAAgB,SAAmC;AACjE,SAAO,QACJ,MAAM,GAAG,EACT,IAAI,CAAC,WAAW,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;AACzD;AAKO,SAAS,iBAAiB,QAA0C;AACzE,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AA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G,YAAY,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC3F,QAAM,iBAAiB,kBAAkB,GAAG,eAAe,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AACjF,QAAM,YAAY,kBAAkB,YAAY,IAAI,GAAG,YAAY,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AACzF,QAAM,eAAe,kBAAkB,GAAG,eAAe,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC/E,QAAM,QAAQ,cAAc;AAC5B,QAAM,MAAM,YAAY;AAExB,SAAO,CAAC,OAAO,GAAG;AACpB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -51,6 +51,9 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
51
51
|
BaseClass,
|
|
52
52
|
options
|
|
53
53
|
) {
|
|
54
|
+
/**
|
|
55
|
+
* Config.
|
|
56
|
+
*/
|
|
54
57
|
static config = {
|
|
55
58
|
name: `${BaseClass.config.name}WithMountWhenInView`,
|
|
56
59
|
emits: ["scrolledInView"],
|
|
@@ -130,8 +133,23 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
130
133
|
}
|
|
131
134
|
return this.__props;
|
|
132
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Factor used for the `dampedProgress` props.
|
|
138
|
+
*
|
|
139
|
+
* @deprecated
|
|
140
|
+
* @todo v3 delete in favor of option API
|
|
141
|
+
*/
|
|
133
142
|
dampFactor = null;
|
|
143
|
+
/**
|
|
144
|
+
* Precision for the `dampedProgress` props.
|
|
145
|
+
*
|
|
146
|
+
* @deprecated
|
|
147
|
+
* @todo v3 delete in favor of option API
|
|
148
|
+
*/
|
|
134
149
|
dampPrecision = null;
|
|
150
|
+
/**
|
|
151
|
+
* Bind listeners.
|
|
152
|
+
*/
|
|
135
153
|
constructor(element) {
|
|
136
154
|
super(element);
|
|
137
155
|
const render = () => {
|
|
@@ -184,26 +202,41 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
184
202
|
render();
|
|
185
203
|
});
|
|
186
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Mounted hook.
|
|
207
|
+
*/
|
|
187
208
|
mounted() {
|
|
188
209
|
if ((0, import_utils.isFunction)(super.mounted)) {
|
|
189
210
|
super.mounted();
|
|
190
211
|
}
|
|
191
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Resized hook.
|
|
215
|
+
*/
|
|
192
216
|
resized(props) {
|
|
193
217
|
if ((0, import_utils.isFunction)(super.resized)) {
|
|
194
218
|
super.resized(props);
|
|
195
219
|
}
|
|
196
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Scrolled hook.
|
|
223
|
+
*/
|
|
197
224
|
scrolled(props) {
|
|
198
225
|
if ((0, import_utils.isFunction)(super.scrolled)) {
|
|
199
226
|
super.scrolled(props);
|
|
200
227
|
}
|
|
201
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Ticked hook.
|
|
231
|
+
*/
|
|
202
232
|
ticked(props) {
|
|
203
233
|
if ((0, import_utils.isFunction)(super.ticked)) {
|
|
204
234
|
super.ticked(props);
|
|
205
235
|
}
|
|
206
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Destroyed hook.
|
|
239
|
+
*/
|
|
207
240
|
destroyed() {
|
|
208
241
|
if ((0, import_utils.isFunction)(super.destroyed)) {
|
|
209
242
|
super.destroyed();
|
|
@@ -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 { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\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(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\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 name: `${BaseClass.config.name}WithMountWhenInView`,\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.pageYOffset;\n targetSizes.x += window.pageXOffset;\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.pageYOffset, 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.pageXOffset, 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 * Factor used for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\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('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\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 * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iCAAoC;AACpC,mBAOO;AACP,IAAAA,gBAA0C;AAE1C,IAAM,gBAAY,2BAAa,CAAC,UAAU,QAAQ,CAAC;AAyCnD,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,
|
|
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 { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\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(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\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 name: `${BaseClass.config.name}WithMountWhenInView`,\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.pageYOffset;\n targetSizes.x += window.pageXOffset;\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.pageYOffset, 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.pageXOffset, 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 * Factor used for the `dampedProgress` props.\n *\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n *\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\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('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\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 * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iCAAoC;AACpC,mBAOO;AACP,IAAAA,gBAA0C;AAE1C,IAAM,gBAAY,2BAAa,CAAC,UAAU,QAAQ,CAAC;AAyCnD,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,WAAW,EAAE,IAAI,IACrB,MAAM,MAAM,IAAI,MAAM,MAAM,IAAI,IAAI,IAChC,QACA;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,QAAI;AAAA,IACpB,SAAS,MAAM,OAAO,cAAc,OAAO;AAAA,IAC3C,MAAM,MAAM,IAAI;AAAA,IAChB,MAAM,IAAI,IAAI;AAAA,EAChB;AACA,QAAM,cAAc,IAAI,QAAI;AAAA,IAC1B,MAAM,QAAQ,IAAI;AAAA,IAClB,MAAM,cAAc,IAAI;AAAA,IACxB;AAA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D,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,aAAK,QAAQ,eAAe,IAAI,KAAK,QAAQ,SAAS;AACtD,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,UAAU;AAER,cAAI,yBAAW,MAAM,OAAO,GAAG;AAE7B,cAAM,QAAQ;AAAA,MAChB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,OAA2B;AAEjC,cAAI,yBAAW,MAAM,OAAO,GAAG;AAE7B,cAAM,QAAQ,KAAK;AAAA,MACrB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS,OAA2B;AAElC,cAAI,yBAAW,MAAM,QAAQ,GAAG;AAE9B,cAAM,SAAS,KAAK;AAAA,MACtB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,OAAwB;AAE7B,cAAI,yBAAW,MAAM,MAAM,GAAG;AAE5B,cAAM,OAAO,KAAK;AAAA,MACpB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY;AAEV,cAAI,yBAAW,MAAM,SAAS,GAAG;AAE/B,cAAM,UAAU;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -34,6 +34,9 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
34
34
|
BaseClass,
|
|
35
35
|
options
|
|
36
36
|
) {
|
|
37
|
+
/**
|
|
38
|
+
* Config.
|
|
39
|
+
*/
|
|
37
40
|
static config = {
|
|
38
41
|
name: `${BaseClass.config.name}WithMountWhenInView`,
|
|
39
42
|
emits: ["scrolledInView"],
|
|
@@ -113,8 +116,23 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
113
116
|
}
|
|
114
117
|
return this.__props;
|
|
115
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Factor used for the `dampedProgress` props.
|
|
121
|
+
*
|
|
122
|
+
* @deprecated
|
|
123
|
+
* @todo v3 delete in favor of option API
|
|
124
|
+
*/
|
|
116
125
|
dampFactor = null;
|
|
126
|
+
/**
|
|
127
|
+
* Precision for the `dampedProgress` props.
|
|
128
|
+
*
|
|
129
|
+
* @deprecated
|
|
130
|
+
* @todo v3 delete in favor of option API
|
|
131
|
+
*/
|
|
117
132
|
dampPrecision = null;
|
|
133
|
+
/**
|
|
134
|
+
* Bind listeners.
|
|
135
|
+
*/
|
|
118
136
|
constructor(element) {
|
|
119
137
|
super(element);
|
|
120
138
|
const render = () => {
|
|
@@ -167,26 +185,41 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
167
185
|
render();
|
|
168
186
|
});
|
|
169
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Mounted hook.
|
|
190
|
+
*/
|
|
170
191
|
mounted() {
|
|
171
192
|
if (isFunction(super.mounted)) {
|
|
172
193
|
super.mounted();
|
|
173
194
|
}
|
|
174
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Resized hook.
|
|
198
|
+
*/
|
|
175
199
|
resized(props) {
|
|
176
200
|
if (isFunction(super.resized)) {
|
|
177
201
|
super.resized(props);
|
|
178
202
|
}
|
|
179
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Scrolled hook.
|
|
206
|
+
*/
|
|
180
207
|
scrolled(props) {
|
|
181
208
|
if (isFunction(super.scrolled)) {
|
|
182
209
|
super.scrolled(props);
|
|
183
210
|
}
|
|
184
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Ticked hook.
|
|
214
|
+
*/
|
|
185
215
|
ticked(props) {
|
|
186
216
|
if (isFunction(super.ticked)) {
|
|
187
217
|
super.ticked(props);
|
|
188
218
|
}
|
|
189
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Destroyed hook.
|
|
222
|
+
*/
|
|
190
223
|
destroyed() {
|
|
191
224
|
if (isFunction(super.destroyed)) {
|
|
192
225
|
super.destroyed();
|
|
@@ -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 { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\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(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\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 name: `${BaseClass.config.name}WithMountWhenInView`,\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.pageYOffset;\n targetSizes.x += window.pageXOffset;\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.pageYOffset, 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.pageXOffset, 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 * Factor used for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\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('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\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 * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
-
"mappings": "AAOA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,gBAAgB;AAE1C,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AAyCnD,SAAS,eACP,OACA,MACA,aACA,YACA;AACA,QAAM,
|
|
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 { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\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(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\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 name: `${BaseClass.config.name}WithMountWhenInView`,\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.pageYOffset;\n targetSizes.x += window.pageXOffset;\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.pageYOffset, 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.pageXOffset, 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 * Factor used for the `dampedProgress` props.\n *\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n *\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\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('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\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 * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,gBAAgB;AAE1C,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AAyCnD,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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
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withVue2.ts"],
|
|
4
4
|
"sourcesContent": ["import type Vue from 'vue';\nimport type { ComponentOptions, VueConstructor } from 'vue';\nimport type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseConfig, BaseProps } from '../Base/index.js';\nimport { isDev, isFunction } from '../utils/index.js';\n\nexport interface WithVue2Props extends BaseProps {\n $refs: {\n vue: HTMLElement;\n };\n}\n\nexport interface WithVue2Interface extends BaseInterface {\n $vue: Vue;\n}\n\n/**\n * withVue decorator.\n */\nexport function withVue2<S extends Base, T extends Vue = Vue>(\n BaseClass: typeof Base,\n VueCtor: VueConstructor,\n): BaseDecorator<WithVue2Interface, S, WithVue2Props> {\n type VueConfig = ComponentOptions<T> & {\n render: ComponentOptions<T>['render'];\n };\n\n /**\n * Class.\n */\n class WithVue2 extends BaseClass {\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithVue`,\n refs: [...(BaseClass.config?.refs ?? []), 'vue'],\n };\n\n $vue: Vue;\n\n /**\n * Vue app configuration.\n */\n static vueConfig: VueConfig;\n\n constructor(element: HTMLElement) {\n super(element);\n\n // @ts-ignore\n const vueConfig: VueConfig = this.vueConfig ?? this.constructor.vueConfig;\n\n if (!vueConfig) {\n if (isDev) {\n throw new Error('[withVue] You must define a `vueConfig` object.');\n }\n return;\n }\n\n if (!isFunction(vueConfig.render)) {\n if (isDev) {\n throw new Error('[withVue] You must define a `render` function in vueConfig.');\n }\n return;\n }\n\n this.$vue = new VueCtor(vueConfig);\n\n this.$on('mounted', () => {\n if (!(this.$refs.vue instanceof HTMLElement)) {\n throw new Error('[withVue] The `vue` refs must be a single HTMLElement.');\n }\n\n this.$vue.$mount(this.$refs.vue);\n });\n\n this.$on('destroyed', () => {\n this.$vue.$destroy();\n });\n }\n }\n\n // @ts-ignore\n return WithVue2;\n}\n"],
|
|
5
|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
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withVue2.ts"],
|
|
4
4
|
"sourcesContent": ["import type Vue from 'vue';\nimport type { ComponentOptions, VueConstructor } from 'vue';\nimport type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseConfig, BaseProps } from '../Base/index.js';\nimport { isDev, isFunction } from '../utils/index.js';\n\nexport interface WithVue2Props extends BaseProps {\n $refs: {\n vue: HTMLElement;\n };\n}\n\nexport interface WithVue2Interface extends BaseInterface {\n $vue: Vue;\n}\n\n/**\n * withVue decorator.\n */\nexport function withVue2<S extends Base, T extends Vue = Vue>(\n BaseClass: typeof Base,\n VueCtor: VueConstructor,\n): BaseDecorator<WithVue2Interface, S, WithVue2Props> {\n type VueConfig = ComponentOptions<T> & {\n render: ComponentOptions<T>['render'];\n };\n\n /**\n * Class.\n */\n class WithVue2 extends BaseClass {\n static config: BaseConfig = {\n ...BaseClass.config,\n name: `${BaseClass.config.name}WithVue`,\n refs: [...(BaseClass.config?.refs ?? []), 'vue'],\n };\n\n $vue: Vue;\n\n /**\n * Vue app configuration.\n */\n static vueConfig: VueConfig;\n\n constructor(element: HTMLElement) {\n super(element);\n\n // @ts-ignore\n const vueConfig: VueConfig = this.vueConfig ?? this.constructor.vueConfig;\n\n if (!vueConfig) {\n if (isDev) {\n throw new Error('[withVue] You must define a `vueConfig` object.');\n }\n return;\n }\n\n if (!isFunction(vueConfig.render)) {\n if (isDev) {\n throw new Error('[withVue] You must define a `render` function in vueConfig.');\n }\n return;\n }\n\n this.$vue = new VueCtor(vueConfig);\n\n this.$on('mounted', () => {\n if (!(this.$refs.vue instanceof HTMLElement)) {\n throw new Error('[withVue] The `vue` refs must be a single HTMLElement.');\n }\n\n this.$vue.$mount(this.$refs.vue);\n });\n\n this.$on('destroyed', () => {\n this.$vue.$destroy();\n });\n }\n }\n\n // @ts-ignore\n return WithVue2;\n}\n"],
|
|
5
|
-
"mappings": "AAIA,SAAS,OAAO,kBAAkB;AAe3B,SAAS,SACd,WACA,SACoD;
|
|
5
|
+
"mappings": "AAIA,SAAS,OAAO,kBAAkB;AAe3B,SAAS,SACd,WACA,SACoD;AAAA,EAQpD,MAAM,iBAAiB,UAAU;AAAA,IAC/B,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,MAAM,CAAC,GAAI,UAAU,QAAQ,QAAQ,CAAC,GAAI,KAAK;AAAA,IACjD;AAAA,IAEA;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO;AAAA,IAEP,YAAY,SAAsB;AAChC,YAAM,OAAO;AAGb,YAAM,YAAuB,KAAK,aAAa,KAAK,YAAY;AAEhE,UAAI,CAAC,WAAW;AACd,YAAI,OAAO;AACT,gBAAM,IAAI,MAAM,iDAAiD;AAAA,QACnE;AACA;AAAA,MACF;AAEA,UAAI,CAAC,WAAW,UAAU,MAAM,GAAG;AACjC,YAAI,OAAO;AACT,gBAAM,IAAI,MAAM,6DAA6D;AAAA,QAC/E;AACA;AAAA,MACF;AAEA,WAAK,OAAO,IAAI,QAAQ,SAAS;AAEjC,WAAK,IAAI,WAAW,MAAM;AACxB,YAAI,EAAE,KAAK,MAAM,eAAe,cAAc;AAC5C,gBAAM,IAAI,MAAM,wDAAwD;AAAA,QAC1E;AAEA,aAAK,KAAK,OAAO,KAAK,MAAM,GAAG;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,KAAK,SAAS;AAAA,MACrB,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/helpers/createApp.cjs
CHANGED
|
@@ -28,9 +28,9 @@ function createApp(App, rootElement = document.body) {
|
|
|
28
28
|
let app;
|
|
29
29
|
const options = rootElement instanceof HTMLElement ? { root: rootElement, features: void 0 } : { root: document.body, ...rootElement };
|
|
30
30
|
if ((0, import_utils.isDefined)(options.features)) {
|
|
31
|
-
Object.entries(options.features)
|
|
31
|
+
for (const [feature, value] of Object.entries(options.features)) {
|
|
32
32
|
import_features.features.set(feature, value);
|
|
33
|
-
}
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
function init() {
|
|
36
36
|
app = new App(options.root).$mount();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\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 default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features as Features)
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAyB;AACzB,mBAA0B;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,UAAI,wBAAU,QAAQ,QAAQ,GAAG;AAC/B,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\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 default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n for (const [feature, value] of Object.entries(options.features as Features)) {\n features.set(feature as keyof Features, value);\n }\n }\n\n function init() {\n app = (new App(options.root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('asyncChildren')) {\n p = Promise.resolve(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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAyB;AACzB,mBAA0B;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,UAAI,wBAAU,QAAQ,QAAQ,GAAG;AAC/B,eAAW,CAAC,SAAS,KAAK,KAAK,OAAO,QAAQ,QAAQ,QAAoB,GAAG;AAC3E,+BAAS,IAAI,SAA2B,KAAK;AAAA,IAC/C;AAAA,EACF;AAEA,WAAS,OAAO;AACd,UAAO,IAAI,IAAI,QAAQ,IAAI,EAAkB,OAAO;AACpD,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,yBAAS,IAAI,eAAe,GAAG;AACjC,QAAI,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC5B,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
|
}
|
package/helpers/createApp.js
CHANGED
|
@@ -4,9 +4,9 @@ function createApp(App, rootElement = document.body) {
|
|
|
4
4
|
let app;
|
|
5
5
|
const options = rootElement instanceof HTMLElement ? { root: rootElement, features: void 0 } : { root: document.body, ...rootElement };
|
|
6
6
|
if (isDefined(options.features)) {
|
|
7
|
-
Object.entries(options.features)
|
|
7
|
+
for (const [feature, value] of Object.entries(options.features)) {
|
|
8
8
|
features.set(feature, value);
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
function init() {
|
|
12
12
|
app = new App(options.root).$mount();
|
package/helpers/createApp.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/helpers/createApp.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\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 default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n Object.entries(options.features as Features)
|
|
5
|
-
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,
|
|
4
|
+
"sourcesContent": ["import type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport type { Features } from '../Base/features.js';\nimport { features } from '../Base/features.js';\nimport { isDefined } from '../utils/index.js';\n\nexport type CreateAppOptions = {\n root: HTMLElement;\n features: Features;\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 default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(\n App: S,\n rootElement: HTMLElement | Partial<CreateAppOptions> = document.body,\n): () => Promise<S & Base<T>> {\n let app: S & Base<T>;\n const options =\n rootElement instanceof HTMLElement\n ? { root: rootElement, features: undefined }\n : { root: document.body, ...rootElement };\n\n if (isDefined(options.features)) {\n for (const [feature, value] of Object.entries(options.features as Features)) {\n features.set(feature as keyof Features, value);\n }\n }\n\n function init() {\n app = (new App(options.root) as S & Base<T>).$mount();\n return app;\n }\n\n let p: Promise<S & Base<T>>;\n\n if (features.get('asyncChildren')) {\n p = Promise.resolve(init());\n } else {\n p = new Promise<S & Base<T>>((resolve) => {\n if (document.readyState === 'complete') {\n resolve(init());\n } else {\n document.addEventListener('readystatechange', () => {\n if (document.readyState === 'complete') {\n resolve(init());\n }\n });\n }\n });\n }\n\n return () => p;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAWX,SAAR,UACL,KACA,cAAuD,SAAS,MACpC;AAC5B,MAAI;AACJ,QAAM,UACJ,uBAAuB,cACnB,EAAE,MAAM,aAAa,UAAU,OAAU,IACzC,EAAE,MAAM,SAAS,MAAM,GAAG,YAAY;AAE5C,MAAI,UAAU,QAAQ,QAAQ,GAAG;AAC/B,eAAW,CAAC,SAAS,KAAK,KAAK,OAAO,QAAQ,QAAQ,QAAoB,GAAG;AAC3E,eAAS,IAAI,SAA2B,KAAK;AAAA,IAC/C;AAAA,EACF;AAEA,WAAS,OAAO;AACd,UAAO,IAAI,IAAI,QAAQ,IAAI,EAAkB,OAAO;AACpD,WAAO;AAAA,EACT;AAEA,MAAI;AAEJ,MAAI,SAAS,IAAI,eAAe,GAAG;AACjC,QAAI,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC5B,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
|
}
|