@studiometa/js-toolkit 2.4.0 → 2.4.3
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/index.cjs +10 -3
- package/Base/index.d.ts +76 -17
- package/Base/index.js +6 -2
- package/Base/managers/AbstractManager.cjs +13 -8
- package/Base/managers/AbstractManager.js +13 -8
- package/Base/managers/ChildrenManager.cjs +10 -3
- package/Base/managers/ChildrenManager.js +6 -2
- package/Base/managers/EventsManager.cjs +17 -4
- package/Base/managers/EventsManager.js +13 -3
- package/Base/managers/OptionsManager.cjs +18 -5
- package/Base/managers/OptionsManager.d.ts +1 -1
- package/Base/managers/OptionsManager.js +14 -4
- package/Base/managers/RefsManager.cjs +17 -4
- package/Base/managers/RefsManager.js +13 -3
- package/Base/managers/ResponsiveOptionsManager.cjs +4 -1
- package/Base/managers/ServicesManager.cjs +12 -5
- package/Base/managers/ServicesManager.js +8 -4
- package/Base/utils.cjs +5 -1
- package/Base/utils.js +5 -1
- package/decorators/index.cjs +4 -1
- package/decorators/withBreakpointManager.cjs +4 -1
- package/decorators/withBreakpointObserver.cjs +10 -3
- package/decorators/withBreakpointObserver.js +6 -2
- package/decorators/withDrag.cjs +8 -2
- package/decorators/withDrag.d.ts +8 -1
- package/decorators/withDrag.js +4 -1
- package/decorators/withExtraConfig.cjs +4 -1
- package/decorators/withIntersectionObserver.cjs +9 -6
- package/decorators/withIntersectionObserver.js +9 -6
- package/decorators/withMountWhenInView.cjs +13 -10
- package/decorators/withMountWhenInView.js +13 -10
- package/decorators/withResponsiveOptions.cjs +4 -1
- package/decorators/withScrolledInView.cjs +64 -18
- package/decorators/withScrolledInView.d.ts +26 -5
- package/decorators/withScrolledInView.js +60 -17
- package/helpers/getDirectChildren.d.ts +9 -2
- package/helpers/importWhenIdle.cjs +8 -5
- package/helpers/importWhenIdle.js +8 -5
- package/helpers/index.cjs +4 -1
- package/index.cjs +4 -1
- package/index.d.ts +1 -0
- package/package.json +2 -2
- package/services/drag.cjs +4 -1
- package/services/index.cjs +4 -1
- package/services/index.d.ts +7 -0
- package/services/key.cjs +4 -1
- package/services/resize.cjs +4 -1
- package/services/scroll.cjs +4 -1
- package/utils/collide/index.cjs +4 -1
- package/utils/css/animate.cjs +24 -13
- package/utils/css/animate.js +20 -12
- package/utils/css/index.cjs +4 -1
- package/utils/css/transition.cjs +4 -4
- package/utils/css/transition.js +0 -3
- package/utils/focusTrap.cjs +4 -1
- package/utils/history.cjs +4 -1
- package/utils/history.js +4 -1
- package/utils/index.cjs +4 -1
- package/utils/math/clamp01.cjs +4 -1
- package/utils/math/index.cjs +4 -1
- package/utils/math/inertiaFinalValue.cjs +4 -1
- package/utils/nextTick.cjs +5 -3
- package/utils/nextTick.js +5 -3
- package/utils/object/autoBind.cjs +4 -1
- package/utils/object/index.cjs +4 -1
- package/utils/scrollTo.cjs +4 -1
- package/utils/string/index.cjs +4 -1
- package/utils/string/withLeadingCharacters.cjs +4 -1
- package/utils/string/withLeadingSlash.cjs +4 -1
- package/utils/string/withTrailingCharacters.cjs +4 -1
- package/utils/string/withTrailingSlash.cjs +4 -1
- package/utils/string/withoutLeadingCharactersRecursive.cjs +4 -1
- package/utils/string/withoutLeadingSlash.cjs +4 -1
- package/utils/string/withoutTrailingCharactersRecursive.cjs +4 -1
- package/utils/string/withoutTrailingSlash.cjs +4 -1
- package/utils/tween.cjs +4 -1
|
@@ -58,12 +58,16 @@ class ServicesManager extends AbstractManager {
|
|
|
58
58
|
return this.disable.bind(this, service);
|
|
59
59
|
}
|
|
60
60
|
enableAll() {
|
|
61
|
-
return Object.keys(this.__services).map(
|
|
61
|
+
return Object.keys(this.__services).map(
|
|
62
|
+
(serviceName) => this.enable(serviceName)
|
|
63
|
+
);
|
|
62
64
|
}
|
|
63
65
|
disableAll() {
|
|
64
|
-
Object.keys(this.__services).forEach(
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
Object.keys(this.__services).forEach(
|
|
67
|
+
(serviceName) => {
|
|
68
|
+
this.disable(serviceName);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
67
71
|
}
|
|
68
72
|
disable(service) {
|
|
69
73
|
if (!this.__services[service]) {
|
package/Base/utils.cjs
CHANGED
|
@@ -52,7 +52,11 @@ function getEventTarget(instance, event, config) {
|
|
|
52
52
|
return instance.$el;
|
|
53
53
|
}
|
|
54
54
|
if (import_utils.isDev) {
|
|
55
|
-
console.warn(
|
|
55
|
+
console.warn(
|
|
56
|
+
`[${config.name}]`,
|
|
57
|
+
`The "${event}" event is missing from the configuration and is not a native`,
|
|
58
|
+
`event for the root element of type \`${instance.$el.constructor.name}\`.`
|
|
59
|
+
);
|
|
56
60
|
}
|
|
57
61
|
return instance;
|
|
58
62
|
}
|
package/Base/utils.js
CHANGED
|
@@ -25,7 +25,11 @@ function getEventTarget(instance, event, config) {
|
|
|
25
25
|
return instance.$el;
|
|
26
26
|
}
|
|
27
27
|
if (isDev) {
|
|
28
|
-
console.warn(
|
|
28
|
+
console.warn(
|
|
29
|
+
`[${config.name}]`,
|
|
30
|
+
`The "${event}" event is missing from the configuration and is not a native`,
|
|
31
|
+
`event for the root element of type \`${instance.$el.constructor.name}\`.`
|
|
32
|
+
);
|
|
29
33
|
}
|
|
30
34
|
return instance;
|
|
31
35
|
}
|
package/decorators/index.cjs
CHANGED
|
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
20
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
24
|
|
|
22
25
|
// packages/js-toolkit/decorators/index.js
|
|
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
20
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
24
|
|
|
22
25
|
// packages/js-toolkit/decorators/withBreakpointManager.js
|
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var __publicField = (obj, key, value) => {
|
|
23
26
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -48,7 +51,9 @@ function hasBreakpointConfiguration(instance) {
|
|
|
48
51
|
function testConflictingBreakpointConfiguration(instance) {
|
|
49
52
|
const { activeBreakpoints, inactiveBreakpoints, name } = instance.$options;
|
|
50
53
|
if (activeBreakpoints && inactiveBreakpoints) {
|
|
51
|
-
throw new Error(
|
|
54
|
+
throw new Error(
|
|
55
|
+
`[${name}] Incorrect configuration: the \`activeBreakpoints\` and \`inactiveBreakpoints\` are not compatible.`
|
|
56
|
+
);
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
function addToResize(key, instance) {
|
|
@@ -76,7 +81,9 @@ function withBreakpointObserver(BaseClass) {
|
|
|
76
81
|
const { name } = this.$options;
|
|
77
82
|
if (!props().breakpoint) {
|
|
78
83
|
if (import_utils.isDev) {
|
|
79
|
-
throw new Error(
|
|
84
|
+
throw new Error(
|
|
85
|
+
`[${name}] The \`BreakpointObserver\` class requires breakpoints to be defined.`
|
|
86
|
+
);
|
|
80
87
|
}
|
|
81
88
|
return;
|
|
82
89
|
}
|
|
@@ -22,7 +22,9 @@ function hasBreakpointConfiguration(instance) {
|
|
|
22
22
|
function testConflictingBreakpointConfiguration(instance) {
|
|
23
23
|
const { activeBreakpoints, inactiveBreakpoints, name } = instance.$options;
|
|
24
24
|
if (activeBreakpoints && inactiveBreakpoints) {
|
|
25
|
-
throw new Error(
|
|
25
|
+
throw new Error(
|
|
26
|
+
`[${name}] Incorrect configuration: the \`activeBreakpoints\` and \`inactiveBreakpoints\` are not compatible.`
|
|
27
|
+
);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
function addToResize(key, instance) {
|
|
@@ -50,7 +52,9 @@ function withBreakpointObserver(BaseClass) {
|
|
|
50
52
|
const { name } = this.$options;
|
|
51
53
|
if (!props().breakpoint) {
|
|
52
54
|
if (isDev) {
|
|
53
|
-
throw new Error(
|
|
55
|
+
throw new Error(
|
|
56
|
+
`[${name}] The \`BreakpointObserver\` class requires breakpoints to be defined.`
|
|
57
|
+
);
|
|
54
58
|
}
|
|
55
59
|
return;
|
|
56
60
|
}
|
package/decorators/withDrag.cjs
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var __publicField = (obj, key, value) => {
|
|
23
26
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -37,7 +40,10 @@ function withDrag(BaseClass, { target = (instance) => instance.$el, ...options }
|
|
|
37
40
|
constructor(el) {
|
|
38
41
|
super(el);
|
|
39
42
|
this.$on("mounted", () => {
|
|
40
|
-
this.$services.register(
|
|
43
|
+
this.$services.register(
|
|
44
|
+
"dragged",
|
|
45
|
+
import_drag.default.bind(void 0, target.call(this, this), options)
|
|
46
|
+
);
|
|
41
47
|
this.$services.enable("dragged");
|
|
42
48
|
});
|
|
43
49
|
this.$on("destroyed", () => {
|
package/decorators/withDrag.d.ts
CHANGED
|
@@ -19,5 +19,12 @@ export type Base = import('../Base').default;
|
|
|
19
19
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
20
20
|
export type DragServiceOptions = import('../services/drag').DragServiceOptions;
|
|
21
21
|
export type DragDecoratorOptions = import("../services/drag.js").DragServiceOptions & {
|
|
22
|
-
target?: (this: import("../Base").default
|
|
22
|
+
target?: (this: import("../Base").default<{
|
|
23
|
+
$el: HTMLElement;
|
|
24
|
+
$options: import("../Base").BaseOptions;
|
|
25
|
+
$refs: import("../Base").BaseRefs;
|
|
26
|
+
$children: {
|
|
27
|
+
[name: string]: import("../Base").default<any> | Promise<import("../Base").default<any>>;
|
|
28
|
+
};
|
|
29
|
+
}>, Base: any) => HTMLElement;
|
|
23
30
|
};
|
package/decorators/withDrag.js
CHANGED
|
@@ -11,7 +11,10 @@ function withDrag(BaseClass, { target = (instance) => instance.$el, ...options }
|
|
|
11
11
|
constructor(el) {
|
|
12
12
|
super(el);
|
|
13
13
|
this.$on("mounted", () => {
|
|
14
|
-
this.$services.register(
|
|
14
|
+
this.$services.register(
|
|
15
|
+
"dragged",
|
|
16
|
+
useDrag.bind(void 0, target.call(this, this), options)
|
|
17
|
+
);
|
|
15
18
|
this.$services.enable("dragged");
|
|
16
19
|
});
|
|
17
20
|
this.$on("destroyed", () => {
|
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var __publicField = (obj, key, value) => {
|
|
23
26
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -35,12 +35,15 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
|
|
|
35
35
|
return _b = class extends BaseClass {
|
|
36
36
|
constructor(element) {
|
|
37
37
|
super(element);
|
|
38
|
-
this.$observer = new IntersectionObserver(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
this.$observer = new IntersectionObserver(
|
|
39
|
+
(entries) => {
|
|
40
|
+
this.__callMethod("intersected", entries);
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
...defaultOptions,
|
|
44
|
+
...this.$options.intersectionObserver
|
|
45
|
+
}
|
|
46
|
+
);
|
|
44
47
|
this.$on("mounted", () => {
|
|
45
48
|
this.$observer.observe(this.$el);
|
|
46
49
|
});
|
|
@@ -12,12 +12,15 @@ function withIntersectionObserver(BaseClass, defaultOptions = { threshold: creat
|
|
|
12
12
|
return _b = class extends BaseClass {
|
|
13
13
|
constructor(element) {
|
|
14
14
|
super(element);
|
|
15
|
-
this.$observer = new IntersectionObserver(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
this.$observer = new IntersectionObserver(
|
|
16
|
+
(entries) => {
|
|
17
|
+
this.__callMethod("intersected", entries);
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
...defaultOptions,
|
|
21
|
+
...this.$options.intersectionObserver
|
|
22
|
+
}
|
|
23
|
+
);
|
|
21
24
|
this.$on("mounted", () => {
|
|
22
25
|
this.$observer.observe(this.$el);
|
|
23
26
|
});
|
|
@@ -34,17 +34,20 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
34
34
|
super(element);
|
|
35
35
|
__publicField(this, "__isVisible", false);
|
|
36
36
|
__publicField(this, "__observer");
|
|
37
|
-
this.__observer = new IntersectionObserver(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.__isVisible
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
this.__observer = new IntersectionObserver(
|
|
38
|
+
(entries) => {
|
|
39
|
+
const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
|
|
40
|
+
if (this.__isVisible !== isVisible) {
|
|
41
|
+
this.__isVisible = isVisible;
|
|
42
|
+
if (isVisible) {
|
|
43
|
+
this.$mount();
|
|
44
|
+
} else {
|
|
45
|
+
setTimeout(() => this.$destroy());
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
+
},
|
|
49
|
+
{ ...defaultOptions, ...this.$options.intersectionObserver }
|
|
50
|
+
);
|
|
48
51
|
this.__observer.observe(this.$el);
|
|
49
52
|
this.$on("terminated", () => {
|
|
50
53
|
this.__observer.disconnect();
|
|
@@ -11,17 +11,20 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
|
|
|
11
11
|
super(element);
|
|
12
12
|
__publicField(this, "__isVisible", false);
|
|
13
13
|
__publicField(this, "__observer");
|
|
14
|
-
this.__observer = new IntersectionObserver(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.__isVisible
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
this.__observer = new IntersectionObserver(
|
|
15
|
+
(entries) => {
|
|
16
|
+
const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
|
|
17
|
+
if (this.__isVisible !== isVisible) {
|
|
18
|
+
this.__isVisible = isVisible;
|
|
19
|
+
if (isVisible) {
|
|
20
|
+
this.$mount();
|
|
21
|
+
} else {
|
|
22
|
+
setTimeout(() => this.$destroy());
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
+
},
|
|
26
|
+
{ ...defaultOptions, ...this.$options.intersectionObserver }
|
|
27
|
+
);
|
|
25
28
|
this.__observer.observe(this.$el);
|
|
26
29
|
this.$on("terminated", () => {
|
|
27
30
|
this.__observer.disconnect();
|
|
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
20
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
24
|
|
|
22
25
|
// packages/js-toolkit/decorators/withResponsiveOptions.js
|
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var __publicField = (obj, key, value) => {
|
|
23
26
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -33,6 +36,25 @@ module.exports = __toCommonJS(withScrolledInView_exports);
|
|
|
33
36
|
var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
|
|
34
37
|
var import_utils = require("../utils/index.cjs");
|
|
35
38
|
var scheduler = (0, import_utils.useScheduler)(["update", "render"]);
|
|
39
|
+
function updateProps(props, dampFactor, dampPrecision, axis = "x") {
|
|
40
|
+
props.current[axis] = (0, import_utils.clamp)(
|
|
41
|
+
axis === "x" ? window.pageXOffset : window.pageYOffset,
|
|
42
|
+
props.start[axis],
|
|
43
|
+
props.end[axis]
|
|
44
|
+
);
|
|
45
|
+
props.dampedCurrent[axis] = (0, import_utils.damp)(
|
|
46
|
+
props.current[axis],
|
|
47
|
+
props.dampedCurrent[axis],
|
|
48
|
+
dampFactor,
|
|
49
|
+
dampPrecision
|
|
50
|
+
);
|
|
51
|
+
props.progress[axis] = (0, import_utils.clamp01)(
|
|
52
|
+
(props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
|
|
53
|
+
);
|
|
54
|
+
props.dampedProgress[axis] = (0, import_utils.clamp01)(
|
|
55
|
+
(props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
|
|
56
|
+
);
|
|
57
|
+
}
|
|
36
58
|
function withScrolledInView(BaseClass, options = {}) {
|
|
37
59
|
var _a;
|
|
38
60
|
return _a = class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
|
|
@@ -51,6 +73,10 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
51
73
|
x: 0,
|
|
52
74
|
y: 0
|
|
53
75
|
},
|
|
76
|
+
dampedCurrent: {
|
|
77
|
+
x: 0,
|
|
78
|
+
y: 0
|
|
79
|
+
},
|
|
54
80
|
progress: {
|
|
55
81
|
x: 0,
|
|
56
82
|
y: 0
|
|
@@ -62,6 +88,16 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
62
88
|
});
|
|
63
89
|
__publicField(this, "dampFactor", 0.1);
|
|
64
90
|
__publicField(this, "dampPrecision", 1e-3);
|
|
91
|
+
const render = () => {
|
|
92
|
+
scheduler.update(() => {
|
|
93
|
+
const renderFn = this.__callMethod("scrolledInView", this.__props);
|
|
94
|
+
if ((0, import_utils.isFunction)(renderFn)) {
|
|
95
|
+
scheduler.render(() => {
|
|
96
|
+
renderFn(this.__props);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
65
101
|
const delegate = {
|
|
66
102
|
handleEvent(event) {
|
|
67
103
|
delegate[event.type](event.detail[0]);
|
|
@@ -75,23 +111,12 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
75
111
|
}
|
|
76
112
|
},
|
|
77
113
|
ticked: () => {
|
|
78
|
-
this.__props
|
|
79
|
-
this.__props
|
|
80
|
-
this.__props.
|
|
81
|
-
this.__props.current.y = (0, import_utils.clamp)(window.pageYOffset, this.__props.start.y, this.__props.end.y);
|
|
82
|
-
this.__props.progress.y = (0, import_utils.clamp01)((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
|
|
83
|
-
this.__props.dampedProgress.y = (0, import_utils.damp)(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
|
|
84
|
-
if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
|
|
114
|
+
updateProps(this.__props, this.dampFactor, this.dampPrecision, "x");
|
|
115
|
+
updateProps(this.__props, this.dampFactor, this.dampPrecision, "y");
|
|
116
|
+
if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
|
|
85
117
|
this.$services.disable("ticked");
|
|
86
118
|
}
|
|
87
|
-
|
|
88
|
-
const renderFn = this.__callMethod("scrolledInView", this.__props);
|
|
89
|
-
if ((0, import_utils.isFunction)(renderFn)) {
|
|
90
|
-
scheduler.render(() => {
|
|
91
|
-
renderFn(this.__props);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
});
|
|
119
|
+
render();
|
|
95
120
|
}
|
|
96
121
|
};
|
|
97
122
|
this.$on("before-mounted", () => {
|
|
@@ -106,6 +131,11 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
106
131
|
this.$off("resized", delegate);
|
|
107
132
|
this.$off("scrolled", delegate);
|
|
108
133
|
this.$off("ticked", delegate);
|
|
134
|
+
this.__props.dampedCurrent.x = this.__props.current.x;
|
|
135
|
+
this.__props.dampedCurrent.y = this.__props.current.y;
|
|
136
|
+
this.__props.dampedProgress.x = this.__props.progress.x;
|
|
137
|
+
this.__props.dampedProgress.y = this.__props.progress.y;
|
|
138
|
+
render();
|
|
109
139
|
});
|
|
110
140
|
}
|
|
111
141
|
mounted() {
|
|
@@ -144,10 +174,26 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
144
174
|
this.__props.end.y = yEnd;
|
|
145
175
|
this.__props.current.x = xCurrent;
|
|
146
176
|
this.__props.current.y = yCurrent;
|
|
177
|
+
this.__props.dampedCurrent.x = (0, import_utils.damp)(
|
|
178
|
+
xCurrent,
|
|
179
|
+
this.__props.dampedCurrent.x,
|
|
180
|
+
this.dampFactor,
|
|
181
|
+
this.dampPrecision
|
|
182
|
+
);
|
|
183
|
+
this.__props.dampedCurrent.y = (0, import_utils.damp)(
|
|
184
|
+
yCurrent,
|
|
185
|
+
this.__props.dampedCurrent.y,
|
|
186
|
+
this.dampFactor,
|
|
187
|
+
this.dampPrecision
|
|
188
|
+
);
|
|
147
189
|
this.__props.progress.x = xProgress;
|
|
148
190
|
this.__props.progress.y = yProgress;
|
|
149
|
-
this.__props.dampedProgress.x = (0, import_utils.
|
|
150
|
-
|
|
191
|
+
this.__props.dampedProgress.x = (0, import_utils.clamp01)(
|
|
192
|
+
(this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
|
|
193
|
+
);
|
|
194
|
+
this.__props.dampedProgress.y = (0, import_utils.clamp01)(
|
|
195
|
+
(this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
|
|
196
|
+
);
|
|
151
197
|
}
|
|
152
198
|
}, __publicField(_a, "config", {
|
|
153
199
|
name: `${BaseClass.config.name}WithMountWhenInView`,
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('../Base').default} Base
|
|
3
|
-
* @typedef {import('../Base').BaseConstructor} BaseConstructor
|
|
4
|
-
* @typedef {import('../Base').BaseConfig} BaseConfig
|
|
5
|
-
*/
|
|
6
1
|
/**
|
|
7
2
|
* Add scrolled in view capabilities to a component.
|
|
8
3
|
*
|
|
@@ -17,3 +12,29 @@ export default function withScrolledInView<T extends typeof import("../Base").de
|
|
|
17
12
|
export type Base = import('../Base').default;
|
|
18
13
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
19
14
|
export type BaseConfig = import('../Base').BaseConfig;
|
|
15
|
+
export type ScrollInViewProps = {
|
|
16
|
+
start: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
end: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
current: {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
};
|
|
28
|
+
dampedCurrent: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
progress: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
dampedProgress: {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -7,6 +7,25 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import withMountWhenInView from "./withMountWhenInView.js";
|
|
8
8
|
import { damp, clamp, clamp01, getOffsetSizes, isFunction, useScheduler } from "../utils/index.js";
|
|
9
9
|
const scheduler = useScheduler(["update", "render"]);
|
|
10
|
+
function updateProps(props, dampFactor, dampPrecision, axis = "x") {
|
|
11
|
+
props.current[axis] = clamp(
|
|
12
|
+
axis === "x" ? window.pageXOffset : window.pageYOffset,
|
|
13
|
+
props.start[axis],
|
|
14
|
+
props.end[axis]
|
|
15
|
+
);
|
|
16
|
+
props.dampedCurrent[axis] = damp(
|
|
17
|
+
props.current[axis],
|
|
18
|
+
props.dampedCurrent[axis],
|
|
19
|
+
dampFactor,
|
|
20
|
+
dampPrecision
|
|
21
|
+
);
|
|
22
|
+
props.progress[axis] = clamp01(
|
|
23
|
+
(props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
|
|
24
|
+
);
|
|
25
|
+
props.dampedProgress[axis] = clamp01(
|
|
26
|
+
(props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis])
|
|
27
|
+
);
|
|
28
|
+
}
|
|
10
29
|
function withScrolledInView(BaseClass, options = {}) {
|
|
11
30
|
var _a;
|
|
12
31
|
return _a = class extends withMountWhenInView(BaseClass, options) {
|
|
@@ -25,6 +44,10 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
25
44
|
x: 0,
|
|
26
45
|
y: 0
|
|
27
46
|
},
|
|
47
|
+
dampedCurrent: {
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0
|
|
50
|
+
},
|
|
28
51
|
progress: {
|
|
29
52
|
x: 0,
|
|
30
53
|
y: 0
|
|
@@ -36,6 +59,16 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
36
59
|
});
|
|
37
60
|
__publicField(this, "dampFactor", 0.1);
|
|
38
61
|
__publicField(this, "dampPrecision", 1e-3);
|
|
62
|
+
const render = () => {
|
|
63
|
+
scheduler.update(() => {
|
|
64
|
+
const renderFn = this.__callMethod("scrolledInView", this.__props);
|
|
65
|
+
if (isFunction(renderFn)) {
|
|
66
|
+
scheduler.render(() => {
|
|
67
|
+
renderFn(this.__props);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
39
72
|
const delegate = {
|
|
40
73
|
handleEvent(event) {
|
|
41
74
|
delegate[event.type](event.detail[0]);
|
|
@@ -49,23 +82,12 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
49
82
|
}
|
|
50
83
|
},
|
|
51
84
|
ticked: () => {
|
|
52
|
-
this.__props
|
|
53
|
-
|
|
54
|
-
this.__props.
|
|
55
|
-
this.__props.current.y = clamp(window.pageYOffset, this.__props.start.y, this.__props.end.y);
|
|
56
|
-
this.__props.progress.y = clamp01((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
|
|
57
|
-
this.__props.dampedProgress.y = damp(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
|
|
58
|
-
if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
|
|
85
|
+
updateProps(this.__props, this.dampFactor, this.dampPrecision, "x");
|
|
86
|
+
updateProps(this.__props, this.dampFactor, this.dampPrecision, "y");
|
|
87
|
+
if (this.__props.dampedCurrent.x === this.__props.current.x && this.__props.dampedCurrent.y === this.__props.current.y) {
|
|
59
88
|
this.$services.disable("ticked");
|
|
60
89
|
}
|
|
61
|
-
|
|
62
|
-
const renderFn = this.__callMethod("scrolledInView", this.__props);
|
|
63
|
-
if (isFunction(renderFn)) {
|
|
64
|
-
scheduler.render(() => {
|
|
65
|
-
renderFn(this.__props);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
90
|
+
render();
|
|
69
91
|
}
|
|
70
92
|
};
|
|
71
93
|
this.$on("before-mounted", () => {
|
|
@@ -80,6 +102,11 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
80
102
|
this.$off("resized", delegate);
|
|
81
103
|
this.$off("scrolled", delegate);
|
|
82
104
|
this.$off("ticked", delegate);
|
|
105
|
+
this.__props.dampedCurrent.x = this.__props.current.x;
|
|
106
|
+
this.__props.dampedCurrent.y = this.__props.current.y;
|
|
107
|
+
this.__props.dampedProgress.x = this.__props.progress.x;
|
|
108
|
+
this.__props.dampedProgress.y = this.__props.progress.y;
|
|
109
|
+
render();
|
|
83
110
|
});
|
|
84
111
|
}
|
|
85
112
|
mounted() {
|
|
@@ -118,10 +145,26 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
118
145
|
this.__props.end.y = yEnd;
|
|
119
146
|
this.__props.current.x = xCurrent;
|
|
120
147
|
this.__props.current.y = yCurrent;
|
|
148
|
+
this.__props.dampedCurrent.x = damp(
|
|
149
|
+
xCurrent,
|
|
150
|
+
this.__props.dampedCurrent.x,
|
|
151
|
+
this.dampFactor,
|
|
152
|
+
this.dampPrecision
|
|
153
|
+
);
|
|
154
|
+
this.__props.dampedCurrent.y = damp(
|
|
155
|
+
yCurrent,
|
|
156
|
+
this.__props.dampedCurrent.y,
|
|
157
|
+
this.dampFactor,
|
|
158
|
+
this.dampPrecision
|
|
159
|
+
);
|
|
121
160
|
this.__props.progress.x = xProgress;
|
|
122
161
|
this.__props.progress.y = yProgress;
|
|
123
|
-
this.__props.dampedProgress.x =
|
|
124
|
-
|
|
162
|
+
this.__props.dampedProgress.x = clamp01(
|
|
163
|
+
(this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
|
|
164
|
+
);
|
|
165
|
+
this.__props.dampedProgress.y = clamp01(
|
|
166
|
+
(this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
|
|
167
|
+
);
|
|
125
168
|
}
|
|
126
169
|
}, __publicField(_a, "config", {
|
|
127
170
|
name: `${BaseClass.config.name}WithMountWhenInView`,
|
|
@@ -8,9 +8,16 @@
|
|
|
8
8
|
* @param {Base} parentInstance
|
|
9
9
|
* @param {string} parentName
|
|
10
10
|
* @param {string} childrenName
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {T[]}
|
|
12
12
|
*/
|
|
13
|
-
export function getDirectChildren<T extends import("../Base/index.js").default
|
|
13
|
+
export function getDirectChildren<T extends import("../Base/index.js").default<{
|
|
14
|
+
$el: HTMLElement;
|
|
15
|
+
$options: import("../Base/index.js").BaseOptions;
|
|
16
|
+
$refs: import("../Base/index.js").BaseRefs;
|
|
17
|
+
$children: {
|
|
18
|
+
[name: string]: import("../Base/index.js").default<any> | Promise<import("../Base/index.js").default<any>>;
|
|
19
|
+
};
|
|
20
|
+
}>>(parentInstance: Base, parentName: string, childrenName: string): T[];
|
|
14
21
|
/**
|
|
15
22
|
* Test if a component instance is a direct child from the given component.
|
|
16
23
|
*
|
|
@@ -38,11 +38,14 @@ function importWhenIdle(fn, options) {
|
|
|
38
38
|
resolver(resolve);
|
|
39
39
|
}, timeout);
|
|
40
40
|
} else {
|
|
41
|
-
window.requestIdleCallback(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
window.requestIdleCallback(
|
|
42
|
+
() => {
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
resolver(resolve);
|
|
45
|
+
}, 0);
|
|
46
|
+
},
|
|
47
|
+
{ timeout: options == null ? void 0 : options.timeout }
|
|
48
|
+
);
|
|
46
49
|
}
|
|
47
50
|
});
|
|
48
51
|
}
|