@studiometa/js-toolkit 2.4.1 → 2.4.2
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 +23 -18
- package/Base/index.js +6 -2
- package/Base/managers/AbstractManager.cjs +13 -8
- package/Base/managers/AbstractManager.d.ts +3 -3
- package/Base/managers/AbstractManager.js +13 -8
- package/Base/managers/ChildrenManager.cjs +10 -3
- package/Base/managers/ChildrenManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.js +6 -2
- package/Base/managers/EventsManager.cjs +17 -4
- package/Base/managers/EventsManager.d.ts +3 -3
- package/Base/managers/EventsManager.js +13 -3
- package/Base/managers/OptionsManager.cjs +18 -5
- package/Base/managers/OptionsManager.d.ts +2 -2
- 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.d.ts +1 -1
- package/Base/managers/ServicesManager.js +8 -4
- package/Base/utils.cjs +5 -1
- package/Base/utils.d.ts +2 -2
- package/Base/utils.js +5 -1
- package/decorators/index.cjs +4 -1
- package/decorators/withBreakpointManager.cjs +4 -1
- package/decorators/withBreakpointManager.d.ts +1 -1
- package/decorators/withBreakpointObserver.cjs +10 -3
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js +6 -2
- package/decorators/withDrag.cjs +8 -2
- package/decorators/withDrag.d.ts +2 -4
- package/decorators/withDrag.js +4 -1
- package/decorators/withExtraConfig.cjs +4 -1
- package/decorators/withIntersectionObserver.cjs +9 -6
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js +9 -6
- package/decorators/withMountWhenInView.cjs +13 -10
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js +13 -10
- package/decorators/withResponsiveOptions.cjs +4 -1
- package/decorators/withScrolledInView.cjs +64 -18
- package/decorators/withScrolledInView.d.ts +27 -6
- package/decorators/withScrolledInView.js +60 -17
- package/decorators/withVue2.d.ts +1 -1
- package/helpers/getDirectChildren.d.ts +3 -3
- package/helpers/importOnInteraction.d.ts +2 -2
- package/helpers/importWhenIdle.cjs +8 -5
- package/helpers/importWhenIdle.js +8 -5
- package/helpers/importWhenVisible.d.ts +2 -2
- package/helpers/index.cjs +4 -1
- package/index.cjs +4 -1
- 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
|
@@ -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);
|
|
@@ -84,12 +87,16 @@ var ServicesManager = class extends import_AbstractManager.default {
|
|
|
84
87
|
return this.disable.bind(this, service);
|
|
85
88
|
}
|
|
86
89
|
enableAll() {
|
|
87
|
-
return Object.keys(this.__services).map(
|
|
90
|
+
return Object.keys(this.__services).map(
|
|
91
|
+
(serviceName) => this.enable(serviceName)
|
|
92
|
+
);
|
|
88
93
|
}
|
|
89
94
|
disableAll() {
|
|
90
|
-
Object.keys(this.__services).forEach(
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
Object.keys(this.__services).forEach(
|
|
96
|
+
(serviceName) => {
|
|
97
|
+
this.disable(serviceName);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
93
100
|
}
|
|
94
101
|
disable(service) {
|
|
95
102
|
if (!this.__services[service]) {
|
|
@@ -79,7 +79,7 @@ export default class ServicesManager extends AbstractManager {
|
|
|
79
79
|
*/
|
|
80
80
|
unregister(name: string): void;
|
|
81
81
|
}
|
|
82
|
-
export type Base = import(
|
|
82
|
+
export type Base = import("../index").default<any>;
|
|
83
83
|
export type BaseConstructor = import('../index').BaseConstructor;
|
|
84
84
|
export type ServiceInterface = import('../../services').ServiceInterface<any>;
|
|
85
85
|
export type Services = typeof SERVICES_MAP & Record<string, () => ServiceInterface>;
|
|
@@ -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.d.ts
CHANGED
|
@@ -36,5 +36,5 @@ export function eventIsNative(event: string, element: HTMLElement): boolean;
|
|
|
36
36
|
* @param {import('./index.js').BaseConfig} config
|
|
37
37
|
* @returns {Base|Base['$el']}
|
|
38
38
|
*/
|
|
39
|
-
export function getEventTarget(instance:
|
|
40
|
-
export type Base = import(
|
|
39
|
+
export function getEventTarget(instance: import("./index.js").default<any>, event: string, config: import('./index.js').BaseConfig): import("./index.js").default<any> | import("./index.js").default<any>['$el'];
|
|
40
|
+
export type Base = import("./index.js").default<any>;
|
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
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* @returns {T}
|
|
7
7
|
*/
|
|
8
8
|
export default function withBreakpointManager<T extends typeof import("../Base").default>(BaseClass: T, breakpoints: Array<[string, BaseConstructor]>): T;
|
|
9
|
-
export type Base = import(
|
|
9
|
+
export type Base = import("../Base").default<any>;
|
|
10
10
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
@@ -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
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @returns {T}
|
|
7
7
|
*/
|
|
8
8
|
export default function withBreakpointObserver<T extends typeof import("../Base").default>(BaseClass: T): T;
|
|
9
|
-
export type Base = import(
|
|
9
|
+
export type Base = import("../Base").default<any>;
|
|
10
10
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
11
11
|
export type WithBreakpointObserverOptions = {
|
|
12
12
|
activeBreakpoints?: string;
|
|
@@ -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
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
* @returns {T}
|
|
16
16
|
*/
|
|
17
17
|
export default function withDrag<T extends typeof import("../Base").default>(BaseClass: T, { target, ...options }?: DragDecoratorOptions): T;
|
|
18
|
-
export type Base = import(
|
|
18
|
+
export type Base = import("../Base").default<any>;
|
|
19
19
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
20
20
|
export type DragServiceOptions = import('../services/drag').DragServiceOptions;
|
|
21
|
-
export type DragDecoratorOptions =
|
|
22
|
-
target?: (this: import("../Base").default, Base: any) => HTMLElement;
|
|
23
|
-
};
|
|
21
|
+
export type DragDecoratorOptions = DragDecoratorOptions;
|
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
|
});
|
|
@@ -11,7 +11,7 @@ export default function withIntersectionObserver<T extends typeof import("../Bas
|
|
|
11
11
|
$observer: IntersectionObserver;
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
export type Base = import(
|
|
14
|
+
export type Base = import("../Base").default<any>;
|
|
15
15
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
16
16
|
export type WithIntersectionObserverOptions = {
|
|
17
17
|
intersectionObserver: any;
|
|
@@ -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();
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* @returns {T}
|
|
22
22
|
*/
|
|
23
23
|
export default function withMountWhenInView<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: IntersectionObserverInit): T;
|
|
24
|
-
export type Base = import(
|
|
24
|
+
export type Base = import("../Base").default<any>;
|
|
25
25
|
export type BaseOptions = import('../Base').BaseOptions;
|
|
26
26
|
export type BaseConstructor = import('../Base').BaseConstructor;
|
|
27
27
|
export type WithMountWhenInViewOptions = {
|
|
@@ -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
|
*
|
|
@@ -14,6 +9,32 @@
|
|
|
14
9
|
export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options?: IntersectionObserverInit & {
|
|
15
10
|
useOffsetSizes?: boolean;
|
|
16
11
|
}): T;
|
|
17
|
-
export type Base = import(
|
|
12
|
+
export type Base = import("../Base").default<any>;
|
|
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
|
+
};
|