@studiometa/js-toolkit 2.2.0 → 2.2.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 +3 -4
- package/Base/index.js +1 -2
- package/Base/managers/ServicesManager.cjs +4 -5
- package/Base/managers/ServicesManager.js +4 -5
- package/Base/utils.cjs +1 -5
- package/Base/utils.d.ts +0 -8
- package/Base/utils.js +1 -5
- package/package.json +1 -1
- package/services/drag.cjs +126 -148
- package/services/drag.d.ts +10 -10
- package/services/drag.js +125 -148
- package/services/index.cjs +3 -1
- package/services/index.d.ts +1 -0
- package/services/index.js +3 -1
- package/services/key.cjs +48 -63
- package/services/key.d.ts +0 -8
- package/services/key.js +47 -63
- package/services/load.cjs +24 -40
- package/services/load.d.ts +0 -8
- package/services/load.js +23 -37
- package/services/pointer.cjs +73 -103
- package/services/pointer.d.ts +1 -9
- package/services/pointer.js +72 -100
- package/services/raf.cjs +36 -53
- package/services/raf.d.ts +0 -8
- package/services/raf.js +36 -54
- package/services/resize.cjs +59 -68
- package/services/resize.d.ts +0 -7
- package/services/resize.js +58 -68
- package/services/scroll.cjs +49 -71
- package/services/scroll.js +48 -71
- package/services/service.cjs +68 -0
- package/services/service.d.ts +18 -0
- package/services/service.js +46 -0
- package/utils/css/animate.cjs +4 -8
- package/utils/css/animate.d.ts +16 -15
- package/utils/css/animate.js +3 -7
- package/utils/index.cjs +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/math/createEases.cjs +32 -0
- package/utils/math/createEases.d.ts +18 -0
- package/utils/math/createEases.js +10 -0
- package/utils/math/ease.cjs +15 -22
- package/utils/math/ease.d.ts +16 -33
- package/utils/math/ease.js +1 -8
- package/utils/math/index.cjs +1 -0
- package/utils/math/index.d.ts +1 -0
- package/utils/math/index.js +1 -0
- package/utils/noop.cjs +31 -0
- package/utils/noop.d.ts +12 -0
- package/utils/noop.js +9 -0
- package/services/Service.cjs +0 -76
- package/services/Service.d.ts +0 -76
- package/services/Service.js +0 -55
package/services/scroll.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -19,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
18
|
};
|
|
20
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var __publicField = (obj, key, value) => {
|
|
23
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
21
|
|
|
27
22
|
// packages/js-toolkit/services/scroll.js
|
|
28
23
|
var scroll_exports = {};
|
|
@@ -30,12 +25,41 @@ __export(scroll_exports, {
|
|
|
30
25
|
default: () => useScroll
|
|
31
26
|
});
|
|
32
27
|
module.exports = __toCommonJS(scroll_exports);
|
|
33
|
-
var
|
|
28
|
+
var import_service = require("./service.cjs");
|
|
34
29
|
var import_debounce = __toESM(require("../utils/debounce.cjs"), 1);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
function createScrollService() {
|
|
31
|
+
function updateProps() {
|
|
32
|
+
const yLast = props.y;
|
|
33
|
+
const xLast = props.x;
|
|
34
|
+
if (window.pageYOffset !== props.y) {
|
|
35
|
+
props.y = window.pageYOffset;
|
|
36
|
+
}
|
|
37
|
+
if (window.pageXOffset !== props.x) {
|
|
38
|
+
props.x = window.pageXOffset;
|
|
39
|
+
}
|
|
40
|
+
props.changed.x = props.x !== xLast;
|
|
41
|
+
props.changed.y = props.y !== yLast;
|
|
42
|
+
props.last.x = xLast;
|
|
43
|
+
props.last.y = yLast;
|
|
44
|
+
props.delta.x = props.x - xLast;
|
|
45
|
+
props.delta.y = props.y - yLast;
|
|
46
|
+
props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
|
|
47
|
+
props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
|
|
48
|
+
props.progress.x = props.max.x === 0 ? 1 : props.x / props.max.x;
|
|
49
|
+
props.progress.y = props.max.y === 0 ? 1 : props.y / props.max.y;
|
|
50
|
+
props.direction.x = props.x > xLast ? "RIGHT" : props.x < xLast ? "LEFT" : "NONE";
|
|
51
|
+
props.direction.y = props.y > yLast ? "DOWN" : props.y < yLast ? "UP" : "NONE";
|
|
52
|
+
return props;
|
|
53
|
+
}
|
|
54
|
+
const onScrollDebounced = (0, import_debounce.default)(() => {
|
|
55
|
+
trigger(updateProps());
|
|
56
|
+
}, 100);
|
|
57
|
+
function onScroll() {
|
|
58
|
+
trigger(updateProps());
|
|
59
|
+
onScrollDebounced();
|
|
60
|
+
}
|
|
61
|
+
const { add, remove, has, props, trigger } = (0, import_service.useService)({
|
|
62
|
+
props: {
|
|
39
63
|
x: window.pageXOffset,
|
|
40
64
|
y: window.pageYOffset,
|
|
41
65
|
changed: {
|
|
@@ -62,71 +86,25 @@ var Scroll = class extends import_Service.default {
|
|
|
62
86
|
x: "NONE",
|
|
63
87
|
y: "NONE"
|
|
64
88
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
get debouncedHandler() {
|
|
73
|
-
const debounced = (0, import_debounce.default)(() => {
|
|
74
|
-
this.updateProps();
|
|
75
|
-
this.trigger(this.props);
|
|
76
|
-
}, 100);
|
|
77
|
-
Object.defineProperty(this, "debouncedHandler", {
|
|
78
|
-
value: debounced
|
|
79
|
-
});
|
|
80
|
-
return debounced;
|
|
81
|
-
}
|
|
82
|
-
handleEvent() {
|
|
83
|
-
this.updateProps();
|
|
84
|
-
this.trigger(this.props);
|
|
85
|
-
this.debouncedHandler();
|
|
86
|
-
}
|
|
87
|
-
kill() {
|
|
88
|
-
document.removeEventListener("scroll", this);
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
updateProps() {
|
|
92
|
-
const yLast = this.props.y;
|
|
93
|
-
const xLast = this.props.x;
|
|
94
|
-
if (window.pageYOffset !== this.props.y) {
|
|
95
|
-
this.props.y = window.pageYOffset;
|
|
89
|
+
},
|
|
90
|
+
init() {
|
|
91
|
+
document.addEventListener("scroll", onScroll, { passive: true, capture: true });
|
|
92
|
+
},
|
|
93
|
+
kill() {
|
|
94
|
+
document.removeEventListener("scroll", onScroll);
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.props.delta.y = this.props.y - yLast;
|
|
106
|
-
this.props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
|
|
107
|
-
this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
|
|
108
|
-
this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
|
|
109
|
-
this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
|
|
110
|
-
this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
|
|
111
|
-
this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
|
|
112
|
-
return this.props;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
var instance;
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
add,
|
|
99
|
+
remove,
|
|
100
|
+
has,
|
|
101
|
+
props: () => props
|
|
102
|
+
};
|
|
103
|
+
}
|
|
116
104
|
var scroll;
|
|
117
105
|
function useScroll() {
|
|
118
106
|
if (!scroll) {
|
|
119
|
-
|
|
120
|
-
instance = new Scroll();
|
|
121
|
-
}
|
|
122
|
-
scroll = {
|
|
123
|
-
add: instance.add.bind(instance),
|
|
124
|
-
remove: instance.remove.bind(instance),
|
|
125
|
-
has: instance.has.bind(instance),
|
|
126
|
-
props() {
|
|
127
|
-
return instance.props;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
107
|
+
scroll = createScrollService();
|
|
130
108
|
}
|
|
131
109
|
return scroll;
|
|
132
110
|
}
|
package/services/scroll.js
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
import Service from "./Service.js";
|
|
1
|
+
import { useService } from "./service.js";
|
|
8
2
|
import debounce from "../utils/debounce.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
function createScrollService() {
|
|
4
|
+
function updateProps() {
|
|
5
|
+
const yLast = props.y;
|
|
6
|
+
const xLast = props.x;
|
|
7
|
+
if (window.pageYOffset !== props.y) {
|
|
8
|
+
props.y = window.pageYOffset;
|
|
9
|
+
}
|
|
10
|
+
if (window.pageXOffset !== props.x) {
|
|
11
|
+
props.x = window.pageXOffset;
|
|
12
|
+
}
|
|
13
|
+
props.changed.x = props.x !== xLast;
|
|
14
|
+
props.changed.y = props.y !== yLast;
|
|
15
|
+
props.last.x = xLast;
|
|
16
|
+
props.last.y = yLast;
|
|
17
|
+
props.delta.x = props.x - xLast;
|
|
18
|
+
props.delta.y = props.y - yLast;
|
|
19
|
+
props.max.x = (document.scrollingElement || document.body).scrollWidth - window.innerWidth;
|
|
20
|
+
props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
|
|
21
|
+
props.progress.x = props.max.x === 0 ? 1 : props.x / props.max.x;
|
|
22
|
+
props.progress.y = props.max.y === 0 ? 1 : props.y / props.max.y;
|
|
23
|
+
props.direction.x = props.x > xLast ? "RIGHT" : props.x < xLast ? "LEFT" : "NONE";
|
|
24
|
+
props.direction.y = props.y > yLast ? "DOWN" : props.y < yLast ? "UP" : "NONE";
|
|
25
|
+
return props;
|
|
26
|
+
}
|
|
27
|
+
const onScrollDebounced = debounce(() => {
|
|
28
|
+
trigger(updateProps());
|
|
29
|
+
}, 100);
|
|
30
|
+
function onScroll() {
|
|
31
|
+
trigger(updateProps());
|
|
32
|
+
onScrollDebounced();
|
|
33
|
+
}
|
|
34
|
+
const { add, remove, has, props, trigger } = useService({
|
|
35
|
+
props: {
|
|
13
36
|
x: window.pageXOffset,
|
|
14
37
|
y: window.pageYOffset,
|
|
15
38
|
changed: {
|
|
@@ -36,71 +59,25 @@ class Scroll extends Service {
|
|
|
36
59
|
x: "NONE",
|
|
37
60
|
y: "NONE"
|
|
38
61
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
get debouncedHandler() {
|
|
47
|
-
const debounced = debounce(() => {
|
|
48
|
-
this.updateProps();
|
|
49
|
-
this.trigger(this.props);
|
|
50
|
-
}, 100);
|
|
51
|
-
Object.defineProperty(this, "debouncedHandler", {
|
|
52
|
-
value: debounced
|
|
53
|
-
});
|
|
54
|
-
return debounced;
|
|
55
|
-
}
|
|
56
|
-
handleEvent() {
|
|
57
|
-
this.updateProps();
|
|
58
|
-
this.trigger(this.props);
|
|
59
|
-
this.debouncedHandler();
|
|
60
|
-
}
|
|
61
|
-
kill() {
|
|
62
|
-
document.removeEventListener("scroll", this);
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
updateProps() {
|
|
66
|
-
const yLast = this.props.y;
|
|
67
|
-
const xLast = this.props.x;
|
|
68
|
-
if (window.pageYOffset !== this.props.y) {
|
|
69
|
-
this.props.y = window.pageYOffset;
|
|
70
|
-
}
|
|
71
|
-
if (window.pageXOffset !== this.props.x) {
|
|
72
|
-
this.props.x = window.pageXOffset;
|
|
62
|
+
},
|
|
63
|
+
init() {
|
|
64
|
+
document.addEventListener("scroll", onScroll, { passive: true, capture: true });
|
|
65
|
+
},
|
|
66
|
+
kill() {
|
|
67
|
+
document.removeEventListener("scroll", onScroll);
|
|
73
68
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.props.max.y = (document.scrollingElement || document.body).scrollHeight - window.innerHeight;
|
|
82
|
-
this.props.progress.x = this.props.max.x === 0 ? 1 : this.props.x / this.props.max.x;
|
|
83
|
-
this.props.progress.y = this.props.max.y === 0 ? 1 : this.props.y / this.props.max.y;
|
|
84
|
-
this.props.direction.x = this.props.x > xLast ? "RIGHT" : this.props.x < xLast ? "LEFT" : "NONE";
|
|
85
|
-
this.props.direction.y = this.props.y > yLast ? "DOWN" : this.props.y < yLast ? "UP" : "NONE";
|
|
86
|
-
return this.props;
|
|
87
|
-
}
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
add,
|
|
72
|
+
remove,
|
|
73
|
+
has,
|
|
74
|
+
props: () => props
|
|
75
|
+
};
|
|
88
76
|
}
|
|
89
|
-
let instance;
|
|
90
77
|
let scroll;
|
|
91
78
|
function useScroll() {
|
|
92
79
|
if (!scroll) {
|
|
93
|
-
|
|
94
|
-
instance = new Scroll();
|
|
95
|
-
}
|
|
96
|
-
scroll = {
|
|
97
|
-
add: instance.add.bind(instance),
|
|
98
|
-
remove: instance.remove.bind(instance),
|
|
99
|
-
has: instance.has.bind(instance),
|
|
100
|
-
props() {
|
|
101
|
-
return instance.props;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
80
|
+
scroll = createScrollService();
|
|
104
81
|
}
|
|
105
82
|
return scroll;
|
|
106
83
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/services/service.js
|
|
20
|
+
var service_exports = {};
|
|
21
|
+
__export(service_exports, {
|
|
22
|
+
useService: () => useService
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(service_exports);
|
|
25
|
+
function useService(options) {
|
|
26
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
27
|
+
let isInit = false;
|
|
28
|
+
const { init, kill, props } = options;
|
|
29
|
+
function has(key) {
|
|
30
|
+
return callbacks.has(key);
|
|
31
|
+
}
|
|
32
|
+
function get(key) {
|
|
33
|
+
return callbacks.get(key);
|
|
34
|
+
}
|
|
35
|
+
function add(key, callback) {
|
|
36
|
+
if (has(key)) {
|
|
37
|
+
console.warn(`The key \`${key}\` has already been added.`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (callbacks.size === 0 && !isInit) {
|
|
41
|
+
init();
|
|
42
|
+
isInit = true;
|
|
43
|
+
}
|
|
44
|
+
callbacks.set(key, callback);
|
|
45
|
+
}
|
|
46
|
+
function remove(key) {
|
|
47
|
+
callbacks.delete(key);
|
|
48
|
+
if (callbacks.size === 0 && isInit) {
|
|
49
|
+
kill();
|
|
50
|
+
isInit = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function trigger(p) {
|
|
54
|
+
callbacks.forEach(function forEachCallback(callback) {
|
|
55
|
+
callback(p);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
callbacks,
|
|
60
|
+
props,
|
|
61
|
+
add,
|
|
62
|
+
remove,
|
|
63
|
+
has,
|
|
64
|
+
get,
|
|
65
|
+
trigger
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use a service.
|
|
3
|
+
* @template {Record<string, any>} T
|
|
4
|
+
* @param {{ init: () => void, kill: () => void, props: T }} options
|
|
5
|
+
*/
|
|
6
|
+
export function useService<T extends Record<string, any>>(options: {
|
|
7
|
+
init: () => void;
|
|
8
|
+
kill: () => void;
|
|
9
|
+
props: T;
|
|
10
|
+
}): {
|
|
11
|
+
callbacks: Map<string, (props: T) => any>;
|
|
12
|
+
props: T;
|
|
13
|
+
add: (key: string, callback: (props: T) => any) => void;
|
|
14
|
+
remove: (key: string) => void;
|
|
15
|
+
has: (key: string) => boolean;
|
|
16
|
+
get: (key: string) => (props: T) => any;
|
|
17
|
+
trigger: (p: T) => void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function useService(options) {
|
|
2
|
+
const callbacks = /* @__PURE__ */ new Map();
|
|
3
|
+
let isInit = false;
|
|
4
|
+
const { init, kill, props } = options;
|
|
5
|
+
function has(key) {
|
|
6
|
+
return callbacks.has(key);
|
|
7
|
+
}
|
|
8
|
+
function get(key) {
|
|
9
|
+
return callbacks.get(key);
|
|
10
|
+
}
|
|
11
|
+
function add(key, callback) {
|
|
12
|
+
if (has(key)) {
|
|
13
|
+
console.warn(`The key \`${key}\` has already been added.`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (callbacks.size === 0 && !isInit) {
|
|
17
|
+
init();
|
|
18
|
+
isInit = true;
|
|
19
|
+
}
|
|
20
|
+
callbacks.set(key, callback);
|
|
21
|
+
}
|
|
22
|
+
function remove(key) {
|
|
23
|
+
callbacks.delete(key);
|
|
24
|
+
if (callbacks.size === 0 && isInit) {
|
|
25
|
+
kill();
|
|
26
|
+
isInit = false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function trigger(p) {
|
|
30
|
+
callbacks.forEach(function forEachCallback(callback) {
|
|
31
|
+
callback(p);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
callbacks,
|
|
36
|
+
props,
|
|
37
|
+
add,
|
|
38
|
+
remove,
|
|
39
|
+
has,
|
|
40
|
+
get,
|
|
41
|
+
trigger
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
useService
|
|
46
|
+
};
|
package/utils/css/animate.cjs
CHANGED
|
@@ -31,11 +31,9 @@ var import_isDefined = __toESM(require("../isDefined.cjs"), 1);
|
|
|
31
31
|
var import_transform = __toESM(require("./transform.cjs"), 1);
|
|
32
32
|
var import_raf = __toESM(require("../../services/raf.cjs"), 1);
|
|
33
33
|
var import_scheduler = require("../scheduler.cjs");
|
|
34
|
+
var import_noop = require("../noop.cjs");
|
|
34
35
|
var id = 0;
|
|
35
36
|
var running = /* @__PURE__ */ new WeakMap();
|
|
36
|
-
var raf = (0, import_raf.default)();
|
|
37
|
-
var noop = () => {
|
|
38
|
-
};
|
|
39
37
|
var PROGRESS_PRECISION = 1e-4;
|
|
40
38
|
var CSSUnitConverter = {
|
|
41
39
|
"%": (value, getSizeRef) => value * getSizeRef() / 100,
|
|
@@ -53,12 +51,9 @@ function getAnimationStepValue(val, getSizeRef) {
|
|
|
53
51
|
}
|
|
54
52
|
return CSSUnitConverter[val[1]](val[0], getSizeRef);
|
|
55
53
|
}
|
|
56
|
-
function linear(value) {
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
54
|
function normalizeEase(ease) {
|
|
60
55
|
if (!(0, import_isDefined.default)(ease)) {
|
|
61
|
-
return
|
|
56
|
+
return import_noop.noopValue;
|
|
62
57
|
}
|
|
63
58
|
if (Array.isArray(ease)) {
|
|
64
59
|
return (0, import_easing.cubicBezier)(...ease);
|
|
@@ -119,6 +114,7 @@ function render(element, from, to, progress) {
|
|
|
119
114
|
}
|
|
120
115
|
function animate(element, keyframes, options = {}) {
|
|
121
116
|
var _a;
|
|
117
|
+
const raf = (0, import_raf.default)();
|
|
122
118
|
let progressValue = 0;
|
|
123
119
|
let easedProgress = 0;
|
|
124
120
|
if (!running.has(element)) {
|
|
@@ -131,7 +127,7 @@ function animate(element, keyframes, options = {}) {
|
|
|
131
127
|
let endTime = startTime + duration;
|
|
132
128
|
const key = `animate-${id}`;
|
|
133
129
|
id += 1;
|
|
134
|
-
const { onProgress = noop, onFinish = noop } = options;
|
|
130
|
+
const { onProgress = import_noop.noop, onFinish = import_noop.noop } = options;
|
|
135
131
|
let isRunning = false;
|
|
136
132
|
const keyframesCount = keyframes.length - 1;
|
|
137
133
|
const normalizedKeyframes = keyframes.map((keyframe, index) => {
|
package/utils/css/animate.d.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('./transform.js').TransformProps} TransformProps
|
|
3
|
-
* @typedef {import('../math/ease.js').EasingFunction} EasingFn
|
|
4
3
|
* @typedef {[number, number, number, number]} BezierCurve
|
|
5
|
-
* @typedef {{
|
|
6
|
-
* duration?: number;
|
|
7
|
-
* easing?: EasingFn|BezierCurve;
|
|
8
|
-
* onProgress?: (progress: number, easedProgress: number) => void;
|
|
9
|
-
* onFinish?: (progress: number, easedProgress: number) => void;
|
|
10
|
-
* }} Options
|
|
11
4
|
* @typedef {TransformProps & {
|
|
12
5
|
* opacity?: number;
|
|
13
6
|
* transformOrigin?: string;
|
|
14
|
-
* easing?:
|
|
7
|
+
* easing?: import('../math/createEases.js').EasingFunction|BezierCurve;
|
|
15
8
|
* offset?: number;
|
|
16
9
|
* }} Keyframe
|
|
17
10
|
* @typedef {Keyframe & {
|
|
18
|
-
* easing:
|
|
11
|
+
* easing: import('../math/createEases.js').EasingFunction;
|
|
19
12
|
* offset: number;
|
|
20
13
|
* }} NormalizedKeyframe
|
|
21
14
|
* @typedef {{
|
|
@@ -30,22 +23,30 @@
|
|
|
30
23
|
* Animate an element.
|
|
31
24
|
* @param {HTMLElement} element
|
|
32
25
|
* @param {Keyframe[]} keyframes
|
|
33
|
-
* @param {
|
|
26
|
+
* @param {{
|
|
27
|
+
* duration?: number;
|
|
28
|
+
* easing?: import('../math/createEases.js').EasingFunction|BezierCurve;
|
|
29
|
+
* onProgress?: (progress: number, easedProgress: number) => void;
|
|
30
|
+
* onFinish?: (progress: number, easedProgress: number) => void;
|
|
31
|
+
* }} [options]
|
|
34
32
|
* @returns {Animate}
|
|
35
33
|
*/
|
|
36
|
-
export function animate(element: HTMLElement, keyframes: Keyframe[], options?:
|
|
34
|
+
export function animate(element: HTMLElement, keyframes: Keyframe[], options?: {
|
|
35
|
+
duration?: number;
|
|
36
|
+
easing?: import('../math/createEases.js').EasingFunction | BezierCurve;
|
|
37
|
+
onProgress?: (progress: number, easedProgress: number) => void;
|
|
38
|
+
onFinish?: (progress: number, easedProgress: number) => void;
|
|
39
|
+
}): Animate;
|
|
37
40
|
export type TransformProps = import('./transform.js').TransformProps;
|
|
38
|
-
export type EasingFn = import('../math/ease.js').EasingFunction;
|
|
39
41
|
export type BezierCurve = [number, number, number, number];
|
|
40
|
-
export type Options = Options;
|
|
41
42
|
export type Keyframe = TransformProps & {
|
|
42
43
|
opacity?: number;
|
|
43
44
|
transformOrigin?: string;
|
|
44
|
-
easing?:
|
|
45
|
+
easing?: import('../math/createEases.js').EasingFunction | [number, number, number, number];
|
|
45
46
|
offset?: number;
|
|
46
47
|
};
|
|
47
48
|
export type NormalizedKeyframe = Keyframe & {
|
|
48
|
-
easing:
|
|
49
|
+
easing: import('../math/createEases.js').EasingFunction;
|
|
49
50
|
offset: number;
|
|
50
51
|
};
|
|
51
52
|
export type Animate = {
|
package/utils/css/animate.js
CHANGED
|
@@ -4,11 +4,9 @@ import isDefined from "../isDefined.js";
|
|
|
4
4
|
import transform, { TRANSFORM_PROPS } from "./transform.js";
|
|
5
5
|
import useRaf from "../../services/raf.js";
|
|
6
6
|
import { domScheduler as scheduler } from "../scheduler.js";
|
|
7
|
+
import { noop, noopValue } from "../noop.js";
|
|
7
8
|
let id = 0;
|
|
8
9
|
const running = /* @__PURE__ */ new WeakMap();
|
|
9
|
-
const raf = useRaf();
|
|
10
|
-
const noop = () => {
|
|
11
|
-
};
|
|
12
10
|
const PROGRESS_PRECISION = 1e-4;
|
|
13
11
|
const CSSUnitConverter = {
|
|
14
12
|
"%": (value, getSizeRef) => value * getSizeRef() / 100,
|
|
@@ -26,12 +24,9 @@ function getAnimationStepValue(val, getSizeRef) {
|
|
|
26
24
|
}
|
|
27
25
|
return CSSUnitConverter[val[1]](val[0], getSizeRef);
|
|
28
26
|
}
|
|
29
|
-
function linear(value) {
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
27
|
function normalizeEase(ease) {
|
|
33
28
|
if (!isDefined(ease)) {
|
|
34
|
-
return
|
|
29
|
+
return noopValue;
|
|
35
30
|
}
|
|
36
31
|
if (Array.isArray(ease)) {
|
|
37
32
|
return cubicBezier(...ease);
|
|
@@ -92,6 +87,7 @@ function render(element, from, to, progress) {
|
|
|
92
87
|
}
|
|
93
88
|
function animate(element, keyframes, options = {}) {
|
|
94
89
|
var _a;
|
|
90
|
+
const raf = useRaf();
|
|
95
91
|
let progressValue = 0;
|
|
96
92
|
let easedProgress = 0;
|
|
97
93
|
if (!running.has(element)) {
|
package/utils/index.cjs
CHANGED
|
@@ -56,4 +56,5 @@ __reExport(utils_exports, require("./collide/index.cjs"), module.exports);
|
|
|
56
56
|
__reExport(utils_exports, require("./math/index.cjs"), module.exports);
|
|
57
57
|
__reExport(utils_exports, require("./string/index.cjs"), module.exports);
|
|
58
58
|
__reExport(utils_exports, require("./scheduler.cjs"), module.exports);
|
|
59
|
+
__reExport(utils_exports, require("./noop.cjs"), module.exports);
|
|
59
60
|
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/index.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ export * from "./collide/index.js";
|
|
|
14
14
|
export * from "./math/index.js";
|
|
15
15
|
export * from "./string/index.js";
|
|
16
16
|
export * from "./scheduler.js";
|
|
17
|
+
export * from "./noop.js";
|
|
17
18
|
export { objectToURLSearchParams, push as historyPush, replace as historyReplace } from "./history.js";
|
package/utils/index.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/utils/math/createEases.js
|
|
20
|
+
var createEases_exports = {};
|
|
21
|
+
__export(createEases_exports, {
|
|
22
|
+
createEaseInOut: () => createEaseInOut,
|
|
23
|
+
createEaseOut: () => createEaseOut
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(createEases_exports);
|
|
26
|
+
function createEaseOut(easeIn) {
|
|
27
|
+
return (progress) => 1 - easeIn(1 - progress);
|
|
28
|
+
}
|
|
29
|
+
function createEaseInOut(easeIn) {
|
|
30
|
+
return (progress) => progress === 0 ? 0 : progress === 1 ? 1 : progress < 0.5 ? easeIn(progress * 2) / 2 : 1 - easeIn((1 - progress) * 2) / 2;
|
|
31
|
+
}
|
|
32
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {(progress: number) => number} EasingFunction
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create an out easing function.
|
|
6
|
+
*
|
|
7
|
+
* @param {EasingFunction} easeIn The ease in function.
|
|
8
|
+
* @returns {EasingFunction} The out function.
|
|
9
|
+
*/
|
|
10
|
+
export function createEaseOut(easeIn: EasingFunction): EasingFunction;
|
|
11
|
+
/**
|
|
12
|
+
* Create an in-out easing function.
|
|
13
|
+
*
|
|
14
|
+
* @param {EasingFunction} easeIn The ease in function.
|
|
15
|
+
* @returns {EasingFunction} The in-out function.
|
|
16
|
+
*/
|
|
17
|
+
export function createEaseInOut(easeIn: EasingFunction): EasingFunction;
|
|
18
|
+
export type EasingFunction = (progress: number) => number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function createEaseOut(easeIn) {
|
|
2
|
+
return (progress) => 1 - easeIn(1 - progress);
|
|
3
|
+
}
|
|
4
|
+
function createEaseInOut(easeIn) {
|
|
5
|
+
return (progress) => progress === 0 ? 0 : progress === 1 ? 1 : progress < 0.5 ? easeIn(progress * 2) / 2 : 1 - easeIn((1 - progress) * 2) / 2;
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
createEaseInOut,
|
|
9
|
+
createEaseOut
|
|
10
|
+
};
|