@hanzogui/animation-helpers 2.0.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/LICENSE +21 -0
- package/dist/cjs/index.cjs +31 -0
- package/dist/cjs/index.native.js +34 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/normalizeTransition.cjs +113 -0
- package/dist/cjs/normalizeTransition.native.js +176 -0
- package/dist/cjs/normalizeTransition.native.js.map +1 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.native.js +19 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +3 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/normalizeTransition.mjs +85 -0
- package/dist/esm/normalizeTransition.mjs.map +1 -0
- package/dist/esm/normalizeTransition.native.js +145 -0
- package/dist/esm/normalizeTransition.native.js.map +1 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +10 -0
- package/src/normalizeTransition.ts +255 -0
- package/src/types.ts +57 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +11 -0
- package/types/normalizeTransition.d.ts +54 -0
- package/types/normalizeTransition.d.ts.map +11 -0
- package/types/types.d.ts +56 -0
- package/types/types.d.ts.map +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
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) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
getAnimatedProperties: () => import_normalizeTransition.getAnimatedProperties,
|
|
24
|
+
getAnimationConfigsForKeys: () => import_normalizeTransition.getAnimationConfigsForKeys,
|
|
25
|
+
getAnimationForProperty: () => import_normalizeTransition.getAnimationForProperty,
|
|
26
|
+
getEffectiveAnimation: () => import_normalizeTransition.getEffectiveAnimation,
|
|
27
|
+
hasAnimation: () => import_normalizeTransition.hasAnimation,
|
|
28
|
+
normalizeTransition: () => import_normalizeTransition.normalizeTransition
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_normalizeTransition = require("./normalizeTransition.cjs");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
getAnimatedProperties: () => import_normalizeTransition.getAnimatedProperties,
|
|
26
|
+
getAnimationConfigsForKeys: () => import_normalizeTransition.getAnimationConfigsForKeys,
|
|
27
|
+
getAnimationForProperty: () => import_normalizeTransition.getAnimationForProperty,
|
|
28
|
+
getEffectiveAnimation: () => import_normalizeTransition.getEffectiveAnimation,
|
|
29
|
+
hasAnimation: () => import_normalizeTransition.hasAnimation,
|
|
30
|
+
normalizeTransition: () => import_normalizeTransition.normalizeTransition
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
var import_normalizeTransition = require("./normalizeTransition.native.js");
|
|
34
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","getAnimatedProperties","import_normalizeTransition","getAnimationConfigsForKeys","getAnimationForProperty","getEffectiveAnimation","hasAnimation","normalizeTransition","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,qBAAA,EAAAA,CAAA,KAAAC,0BAAA,CAAAD,qBAAA;EAAAE,0BAAA,EAAAA,CAAA,KAAAD,0BAAA,CAAAC,0BAAA;EAAAC,uBAAA,EAAAA,CAAA,KAAAF,0BAAA,CAAAE,uBAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAH,0BAAA,CAAAG,qBAAA;EAAAC,YAAA,EAAAA,CAAA,KAAAJ,0BAAA,CAAAI,YAAA;EAAAC,mBAAA,EAAAA,CAAA,KAAAL,0BAAA,CAAAK;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAf,YAAA,CAAAK,aAOO","ignoreList":[]}
|
|
@@ -0,0 +1,113 @@
|
|
|
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) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var normalizeTransition_exports = {};
|
|
22
|
+
__export(normalizeTransition_exports, {
|
|
23
|
+
getAnimatedProperties: () => getAnimatedProperties,
|
|
24
|
+
getAnimationConfigsForKeys: () => getAnimationConfigsForKeys,
|
|
25
|
+
getAnimationForProperty: () => getAnimationForProperty,
|
|
26
|
+
getEffectiveAnimation: () => getEffectiveAnimation,
|
|
27
|
+
hasAnimation: () => hasAnimation,
|
|
28
|
+
normalizeTransition: () => normalizeTransition
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(normalizeTransition_exports);
|
|
31
|
+
const SPRING_CONFIG_KEYS = /* @__PURE__ */new Set(["stiffness", "damping", "mass", "tension", "friction", "velocity", "overshootClamping", "duration", "bounciness", "speed"]);
|
|
32
|
+
function isSpringConfigKey(key) {
|
|
33
|
+
return SPRING_CONFIG_KEYS.has(key);
|
|
34
|
+
}
|
|
35
|
+
function normalizeTransition(transition) {
|
|
36
|
+
if (!transition) return {
|
|
37
|
+
default: null,
|
|
38
|
+
enter: null,
|
|
39
|
+
exit: null,
|
|
40
|
+
delay: void 0,
|
|
41
|
+
properties: {}
|
|
42
|
+
};
|
|
43
|
+
if (typeof transition == "string") return {
|
|
44
|
+
default: transition,
|
|
45
|
+
enter: null,
|
|
46
|
+
exit: null,
|
|
47
|
+
delay: void 0,
|
|
48
|
+
properties: {}
|
|
49
|
+
};
|
|
50
|
+
if (Array.isArray(transition)) {
|
|
51
|
+
const [defaultAnimation, configObj] = transition,
|
|
52
|
+
properties = {},
|
|
53
|
+
springConfig = {};
|
|
54
|
+
let delay,
|
|
55
|
+
enter = null,
|
|
56
|
+
exit = null;
|
|
57
|
+
if (configObj && typeof configObj == "object") for (const [key, value] of Object.entries(configObj)) key === "delay" && typeof value == "number" ? delay = value : key === "enter" && typeof value == "string" ? enter = value : key === "exit" && typeof value == "string" ? exit = value : isSpringConfigKey(key) && value !== void 0 ? springConfig[key] = value : value !== void 0 && (properties[key] = value);
|
|
58
|
+
return {
|
|
59
|
+
default: defaultAnimation,
|
|
60
|
+
enter,
|
|
61
|
+
exit,
|
|
62
|
+
delay,
|
|
63
|
+
properties,
|
|
64
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : void 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (typeof transition == "object") {
|
|
68
|
+
const properties = {},
|
|
69
|
+
springConfig = {};
|
|
70
|
+
let defaultAnimation = null,
|
|
71
|
+
enter = null,
|
|
72
|
+
exit = null,
|
|
73
|
+
delay;
|
|
74
|
+
for (const [key, value] of Object.entries(transition)) key === "default" && typeof value == "string" ? defaultAnimation = value : key === "enter" && typeof value == "string" ? enter = value : key === "exit" && typeof value == "string" ? exit = value : key === "delay" && typeof value == "number" ? delay = value : isSpringConfigKey(key) && value !== void 0 ? springConfig[key] = value : value !== void 0 && (properties[key] = value);
|
|
75
|
+
return {
|
|
76
|
+
default: defaultAnimation,
|
|
77
|
+
enter,
|
|
78
|
+
exit,
|
|
79
|
+
delay,
|
|
80
|
+
properties,
|
|
81
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : void 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
default: null,
|
|
86
|
+
enter: null,
|
|
87
|
+
exit: null,
|
|
88
|
+
delay: void 0,
|
|
89
|
+
properties: {}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function getAnimationForProperty(normalized, property) {
|
|
93
|
+
const propertyAnimation = normalized.properties[property];
|
|
94
|
+
return propertyAnimation !== void 0 ? propertyAnimation : normalized.default;
|
|
95
|
+
}
|
|
96
|
+
function hasAnimation(normalized) {
|
|
97
|
+
return normalized.default !== null || normalized.enter !== null || normalized.exit !== null || Object.keys(normalized.properties).length > 0;
|
|
98
|
+
}
|
|
99
|
+
function getAnimatedProperties(normalized) {
|
|
100
|
+
return Object.keys(normalized.properties);
|
|
101
|
+
}
|
|
102
|
+
function getEffectiveAnimation(normalized, state) {
|
|
103
|
+
return state === "enter" && normalized.enter ? normalized.enter : state === "exit" && normalized.exit ? normalized.exit : normalized.default;
|
|
104
|
+
}
|
|
105
|
+
function getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation) {
|
|
106
|
+
const result = /* @__PURE__ */new Map();
|
|
107
|
+
for (const key of keys) {
|
|
108
|
+
const propAnimation = normalized.properties[key];
|
|
109
|
+
let animationValue = null;
|
|
110
|
+
typeof propAnimation == "string" ? animationValue = animations[propAnimation] ?? null : propAnimation && typeof propAnimation == "object" && propAnimation.type && (animationValue = animations[propAnimation.type] ?? null), animationValue === null && (animationValue = defaultAnimation), result.set(key, animationValue);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var normalizeTransition_exports = {};
|
|
24
|
+
__export(normalizeTransition_exports, {
|
|
25
|
+
getAnimatedProperties: () => getAnimatedProperties,
|
|
26
|
+
getAnimationConfigsForKeys: () => getAnimationConfigsForKeys,
|
|
27
|
+
getAnimationForProperty: () => getAnimationForProperty,
|
|
28
|
+
getEffectiveAnimation: () => getEffectiveAnimation,
|
|
29
|
+
hasAnimation: () => hasAnimation,
|
|
30
|
+
normalizeTransition: () => normalizeTransition
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(normalizeTransition_exports);
|
|
33
|
+
function _type_of(obj) {
|
|
34
|
+
"@swc/helpers - typeof";
|
|
35
|
+
|
|
36
|
+
return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
37
|
+
}
|
|
38
|
+
var SPRING_CONFIG_KEYS = /* @__PURE__ */new Set(["stiffness", "damping", "mass", "tension", "friction", "velocity", "overshootClamping", "duration", "bounciness", "speed"]);
|
|
39
|
+
function isSpringConfigKey(key) {
|
|
40
|
+
return SPRING_CONFIG_KEYS.has(key);
|
|
41
|
+
}
|
|
42
|
+
function normalizeTransition(transition) {
|
|
43
|
+
if (!transition) return {
|
|
44
|
+
default: null,
|
|
45
|
+
enter: null,
|
|
46
|
+
exit: null,
|
|
47
|
+
delay: void 0,
|
|
48
|
+
properties: {}
|
|
49
|
+
};
|
|
50
|
+
if (typeof transition == "string") return {
|
|
51
|
+
default: transition,
|
|
52
|
+
enter: null,
|
|
53
|
+
exit: null,
|
|
54
|
+
delay: void 0,
|
|
55
|
+
properties: {}
|
|
56
|
+
};
|
|
57
|
+
if (Array.isArray(transition)) {
|
|
58
|
+
var [defaultAnimation, configObj] = transition,
|
|
59
|
+
properties = {},
|
|
60
|
+
springConfig = {},
|
|
61
|
+
delay,
|
|
62
|
+
enter = null,
|
|
63
|
+
exit = null;
|
|
64
|
+
if (configObj && (typeof configObj > "u" ? "undefined" : _type_of(configObj)) === "object") {
|
|
65
|
+
var _iteratorNormalCompletion = !0,
|
|
66
|
+
_didIteratorError = !1,
|
|
67
|
+
_iteratorError = void 0;
|
|
68
|
+
try {
|
|
69
|
+
for (var _iterator = Object.entries(configObj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
70
|
+
var [key, value] = _step.value;
|
|
71
|
+
key === "delay" && typeof value == "number" ? delay = value : key === "enter" && typeof value == "string" ? enter = value : key === "exit" && typeof value == "string" ? exit = value : isSpringConfigKey(key) && value !== void 0 ? springConfig[key] = value : value !== void 0 && (properties[key] = value);
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
75
|
+
} finally {
|
|
76
|
+
try {
|
|
77
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
78
|
+
} finally {
|
|
79
|
+
if (_didIteratorError) throw _iteratorError;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
default: defaultAnimation,
|
|
85
|
+
enter,
|
|
86
|
+
exit,
|
|
87
|
+
delay,
|
|
88
|
+
properties,
|
|
89
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : void 0
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if ((typeof transition > "u" ? "undefined" : _type_of(transition)) === "object") {
|
|
93
|
+
var properties1 = {},
|
|
94
|
+
springConfig1 = {},
|
|
95
|
+
defaultAnimation1 = null,
|
|
96
|
+
enter1 = null,
|
|
97
|
+
exit1 = null,
|
|
98
|
+
delay1,
|
|
99
|
+
_iteratorNormalCompletion1 = !0,
|
|
100
|
+
_didIteratorError1 = !1,
|
|
101
|
+
_iteratorError1 = void 0;
|
|
102
|
+
try {
|
|
103
|
+
for (var _iterator1 = Object.entries(transition)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
|
|
104
|
+
var [key1, value1] = _step1.value;
|
|
105
|
+
key1 === "default" && typeof value1 == "string" ? defaultAnimation1 = value1 : key1 === "enter" && typeof value1 == "string" ? enter1 = value1 : key1 === "exit" && typeof value1 == "string" ? exit1 = value1 : key1 === "delay" && typeof value1 == "number" ? delay1 = value1 : isSpringConfigKey(key1) && value1 !== void 0 ? springConfig1[key1] = value1 : value1 !== void 0 && (properties1[key1] = value1);
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
_didIteratorError1 = !0, _iteratorError1 = err;
|
|
109
|
+
} finally {
|
|
110
|
+
try {
|
|
111
|
+
!_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
|
|
112
|
+
} finally {
|
|
113
|
+
if (_didIteratorError1) throw _iteratorError1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
default: defaultAnimation1,
|
|
118
|
+
enter: enter1,
|
|
119
|
+
exit: exit1,
|
|
120
|
+
delay: delay1,
|
|
121
|
+
properties: properties1,
|
|
122
|
+
config: Object.keys(springConfig1).length > 0 ? springConfig1 : void 0
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
default: null,
|
|
127
|
+
enter: null,
|
|
128
|
+
exit: null,
|
|
129
|
+
delay: void 0,
|
|
130
|
+
properties: {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function getAnimationForProperty(normalized, property) {
|
|
134
|
+
var propertyAnimation = normalized.properties[property];
|
|
135
|
+
return propertyAnimation !== void 0 ? propertyAnimation : normalized.default;
|
|
136
|
+
}
|
|
137
|
+
function hasAnimation(normalized) {
|
|
138
|
+
return normalized.default !== null || normalized.enter !== null || normalized.exit !== null || Object.keys(normalized.properties).length > 0;
|
|
139
|
+
}
|
|
140
|
+
function getAnimatedProperties(normalized) {
|
|
141
|
+
return Object.keys(normalized.properties);
|
|
142
|
+
}
|
|
143
|
+
function getEffectiveAnimation(normalized, state) {
|
|
144
|
+
return state === "enter" && normalized.enter ? normalized.enter : state === "exit" && normalized.exit ? normalized.exit : normalized.default;
|
|
145
|
+
}
|
|
146
|
+
function getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation) {
|
|
147
|
+
var result = /* @__PURE__ */new Map(),
|
|
148
|
+
_iteratorNormalCompletion = !0,
|
|
149
|
+
_didIteratorError = !1,
|
|
150
|
+
_iteratorError = void 0;
|
|
151
|
+
try {
|
|
152
|
+
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
153
|
+
var key = _step.value,
|
|
154
|
+
propAnimation = normalized.properties[key],
|
|
155
|
+
animationValue = null;
|
|
156
|
+
if (typeof propAnimation == "string") {
|
|
157
|
+
var _animations_propAnimation;
|
|
158
|
+
animationValue = (_animations_propAnimation = animations[propAnimation]) !== null && _animations_propAnimation !== void 0 ? _animations_propAnimation : null;
|
|
159
|
+
} else if (propAnimation && (typeof propAnimation > "u" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type) {
|
|
160
|
+
var _animations_propAnimation_type;
|
|
161
|
+
animationValue = (_animations_propAnimation_type = animations[propAnimation.type]) !== null && _animations_propAnimation_type !== void 0 ? _animations_propAnimation_type : null;
|
|
162
|
+
}
|
|
163
|
+
animationValue === null && (animationValue = defaultAnimation), result.set(key, animationValue);
|
|
164
|
+
}
|
|
165
|
+
} catch (err) {
|
|
166
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
167
|
+
} finally {
|
|
168
|
+
try {
|
|
169
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
170
|
+
} finally {
|
|
171
|
+
if (_didIteratorError) throw _iteratorError;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=normalizeTransition.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","normalizeTransition_exports","__export","getAnimatedProperties","getAnimationConfigsForKeys","getAnimationForProperty","getEffectiveAnimation","hasAnimation","normalizeTransition","module","exports","_type_of","obj","Symbol","constructor","SPRING_CONFIG_KEYS","Set","isSpringConfigKey","key","has","transition","default","enter","exit","delay","properties","Array","isArray","defaultAnimation","configObj","springConfig","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Object","entries","iterator","_step","next","done","err","return","config","keys","length","properties1","springConfig1","defaultAnimation1","enter1","exit1","delay1","_iteratorNormalCompletion1","_didIteratorError1","_iteratorError1","_iterator1","_step1","key1","value1"],"sources":["../../src/normalizeTransition.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,2BAAA;AAAAC,QAAA,CAAAD,2BAAA;EAAAE,qBAAA,EAAAA,CAA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,MAAA,GAAAD,UAAA,CAAAhB,IAAA,IAAAC,IAAA,GAAAY,0BAAA;QAE3B,KAAAK,IAAA,EAAAC,MAAA,IAAoBF,MAAA,CAAAxD,KAAW;QACrCyD,IAAI,yBAAsBC,MACjB,eAAAV,iBAIS,GAAAU,MAAA,GAAAD,IAAA,uBAAAC,MAAA,eAAAT,MAAA,GAAAS,MAAA,GAAAD,IAAA,sBAAAC,MAAA,eAAAR,KAAA,GAAAQ,MAAA,GAAAD,IAAA,uBAAAC,MAAA,eAAAP,MAAA,GAAAO,MAAA,GAAAzC,iBAAA,CAAAwC,IAAA,KAAAC,MAAA,cAAAX,aAAA,CAAAU,IAAA,IAAAC,MAAA,GAAAA,MAAA,gBAAAZ,WAAA,CAAAW,IAAA,IAAAC,MAAA;MACpB;IAKO,SAASjB,GAAA;MACdY,kBACa,OAAAC,eACX,GAAAb,GAAW;IAIf;MAMO,IAAS;QACd,CAAOW,0BAAuB,IAAAG,UAAU,CAAAb,MAAA,YAAAa,UAAA,CAAAb,MAAA;MAC1C;QAUO,IAASW,kBAAA,EAIV,MAAAC,eAAqB;MAO3B;IAYO;IAML,OAAM;MAENjC,OAAW,EAAA2B,iBAAa;MACtB1B,KAAM,EAAA2B,MAAA;MACN1B,IAAI,EAAA2B,KAAA;MAEA1B,KAAO,EAAA2B,MAAA;MAgBb1B,UAAA,EAAAqB,WAAA;MAEAH,MAAO,EAAAR,MAAA,CAAAS,IAAA,CAAAG,aAAA,EAAAF,MAAA,OAAAE,aAAA;IACT","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
+
value: !0
|
|
16
|
+
}), mod);
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","types_exports"],"sources":["../../src/types.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { normalizeTransition, getAnimationForProperty, hasAnimation, getAnimatedProperties, getEffectiveAnimation, getAnimationConfigsForKeys } from "./normalizeTransition.mjs";
|
|
2
|
+
export { getAnimatedProperties, getAnimationConfigsForKeys, getAnimationForProperty, getEffectiveAnimation, hasAnimation, normalizeTransition };
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["normalizeTransition","getAnimationForProperty","hasAnimation","getAnimatedProperties","getEffectiveAnimation","getAnimationConfigsForKeys"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SACEA,mBAAA,EACAC,uBAAA,EACAC,YAAA,EACAC,qBAAA,EACAC,qBAAA,EACAC,0BAAA,QACK","ignoreList":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { normalizeTransition, getAnimationForProperty, hasAnimation, getAnimatedProperties, getEffectiveAnimation, getAnimationConfigsForKeys } from "./normalizeTransition.mjs";
|
|
2
|
+
export { getAnimatedProperties, getAnimationConfigsForKeys, getAnimationForProperty, getEffectiveAnimation, hasAnimation, normalizeTransition };
|
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["normalizeTransition","getAnimationForProperty","hasAnimation","getAnimatedProperties","getEffectiveAnimation","getAnimationConfigsForKeys"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SACEA,mBAAA,EACAC,uBAAA,EACAC,YAAA,EACAC,qBAAA,EACAC,qBAAA,EACAC,0BAAA,QACK","ignoreList":[]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { normalizeTransition, getAnimationForProperty, hasAnimation, getAnimatedProperties, getEffectiveAnimation, getAnimationConfigsForKeys } from "./normalizeTransition.native.js";
|
|
2
|
+
export { getAnimatedProperties, getAnimationConfigsForKeys, getAnimationForProperty, getEffectiveAnimation, hasAnimation, normalizeTransition };
|
|
3
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["normalizeTransition","getAnimationForProperty","hasAnimation","getAnimatedProperties","getEffectiveAnimation","getAnimationConfigsForKeys"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAAAA,mBAAA,EAAAC,uBAAA,EAAAC,YAAA,EAAAC,qBAAA,EAAAC,qBAAA,EAAAC,0BAAA;AAAA,SAEEF,qBAAA,EACAE,0BAAA,EACAJ,uBAAA,EACAG,qBAAA,EACAF,YAAA,EAAAF,mBACK","ignoreList":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const SPRING_CONFIG_KEYS = /* @__PURE__ */new Set(["stiffness", "damping", "mass", "tension", "friction", "velocity", "overshootClamping", "duration", "bounciness", "speed"]);
|
|
2
|
+
function isSpringConfigKey(key) {
|
|
3
|
+
return SPRING_CONFIG_KEYS.has(key);
|
|
4
|
+
}
|
|
5
|
+
function normalizeTransition(transition) {
|
|
6
|
+
if (!transition) return {
|
|
7
|
+
default: null,
|
|
8
|
+
enter: null,
|
|
9
|
+
exit: null,
|
|
10
|
+
delay: void 0,
|
|
11
|
+
properties: {}
|
|
12
|
+
};
|
|
13
|
+
if (typeof transition == "string") return {
|
|
14
|
+
default: transition,
|
|
15
|
+
enter: null,
|
|
16
|
+
exit: null,
|
|
17
|
+
delay: void 0,
|
|
18
|
+
properties: {}
|
|
19
|
+
};
|
|
20
|
+
if (Array.isArray(transition)) {
|
|
21
|
+
const [defaultAnimation, configObj] = transition,
|
|
22
|
+
properties = {},
|
|
23
|
+
springConfig = {};
|
|
24
|
+
let delay,
|
|
25
|
+
enter = null,
|
|
26
|
+
exit = null;
|
|
27
|
+
if (configObj && typeof configObj == "object") for (const [key, value] of Object.entries(configObj)) key === "delay" && typeof value == "number" ? delay = value : key === "enter" && typeof value == "string" ? enter = value : key === "exit" && typeof value == "string" ? exit = value : isSpringConfigKey(key) && value !== void 0 ? springConfig[key] = value : value !== void 0 && (properties[key] = value);
|
|
28
|
+
return {
|
|
29
|
+
default: defaultAnimation,
|
|
30
|
+
enter,
|
|
31
|
+
exit,
|
|
32
|
+
delay,
|
|
33
|
+
properties,
|
|
34
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : void 0
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (typeof transition == "object") {
|
|
38
|
+
const properties = {},
|
|
39
|
+
springConfig = {};
|
|
40
|
+
let defaultAnimation = null,
|
|
41
|
+
enter = null,
|
|
42
|
+
exit = null,
|
|
43
|
+
delay;
|
|
44
|
+
for (const [key, value] of Object.entries(transition)) key === "default" && typeof value == "string" ? defaultAnimation = value : key === "enter" && typeof value == "string" ? enter = value : key === "exit" && typeof value == "string" ? exit = value : key === "delay" && typeof value == "number" ? delay = value : isSpringConfigKey(key) && value !== void 0 ? springConfig[key] = value : value !== void 0 && (properties[key] = value);
|
|
45
|
+
return {
|
|
46
|
+
default: defaultAnimation,
|
|
47
|
+
enter,
|
|
48
|
+
exit,
|
|
49
|
+
delay,
|
|
50
|
+
properties,
|
|
51
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : void 0
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
default: null,
|
|
56
|
+
enter: null,
|
|
57
|
+
exit: null,
|
|
58
|
+
delay: void 0,
|
|
59
|
+
properties: {}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getAnimationForProperty(normalized, property) {
|
|
63
|
+
const propertyAnimation = normalized.properties[property];
|
|
64
|
+
return propertyAnimation !== void 0 ? propertyAnimation : normalized.default;
|
|
65
|
+
}
|
|
66
|
+
function hasAnimation(normalized) {
|
|
67
|
+
return normalized.default !== null || normalized.enter !== null || normalized.exit !== null || Object.keys(normalized.properties).length > 0;
|
|
68
|
+
}
|
|
69
|
+
function getAnimatedProperties(normalized) {
|
|
70
|
+
return Object.keys(normalized.properties);
|
|
71
|
+
}
|
|
72
|
+
function getEffectiveAnimation(normalized, state) {
|
|
73
|
+
return state === "enter" && normalized.enter ? normalized.enter : state === "exit" && normalized.exit ? normalized.exit : normalized.default;
|
|
74
|
+
}
|
|
75
|
+
function getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation) {
|
|
76
|
+
const result = /* @__PURE__ */new Map();
|
|
77
|
+
for (const key of keys) {
|
|
78
|
+
const propAnimation = normalized.properties[key];
|
|
79
|
+
let animationValue = null;
|
|
80
|
+
typeof propAnimation == "string" ? animationValue = animations[propAnimation] ?? null : propAnimation && typeof propAnimation == "object" && propAnimation.type && (animationValue = animations[propAnimation.type] ?? null), animationValue === null && (animationValue = defaultAnimation), result.set(key, animationValue);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
export { getAnimatedProperties, getAnimationConfigsForKeys, getAnimationForProperty, getEffectiveAnimation, hasAnimation, normalizeTransition };
|
|
85
|
+
//# sourceMappingURL=normalizeTransition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SPRING_CONFIG_KEYS","Set","isSpringConfigKey","key","has","normalizeTransition","transition","default","enter","exit","delay","properties","Array","isArray","defaultAnimation","configObj","springConfig","value","Object","entries","config","keys","length","getAnimationForProperty","normalized","property","propertyAnimation","hasAnimation","getAnimatedProperties","getEffectiveAnimation","state","getAnimationConfigsForKeys","animations","result","Map","propAnimation","animationValue","type","set"],"sources":["../../src/normalizeTransition.ts"],"sourcesContent":[null],"mappings":"AAOA,MAAMA,kBAAA,GAAkC,mBAAIC,GAAA,CAAI,CAC9C,aACA,WACA,QACA,WACA,YACA,YACA,qBACA,YACA,cACA,QACD;AAKD,SAASC,kBAAkBC,GAAA,EAAwC;EACjE,OAAOH,kBAAA,CAAmBI,GAAA,CAAID,GAAG;AACnC;AAcO,SAASE,oBACdC,UAAA,EACsB;EAEtB,IAAI,CAACA,UAAA,EACH,OAAO;IACLC,OA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QACpBS,MAAA,CAAOG,IAAA,CAAKG,UAAA,CAAWb,UAAU,EAAEW,MAAA,GAAS;AAEhD;AAMO,SAASM,sBAAsBJ,UAAA,EAA4C;EAChF,OAAON,MAAA,CAAOG,IAAA,CAAKG,UAAA,CAAWb,UAAU;AAC1C;AAUO,SAASkB,sBACdL,UAAA,EACAM,KAAA,EACe;EACf,OAAIA,KAAA,KAAU,WAAWN,UAAA,CAAWhB,KAAA,GAC3BgB,UAAA,CAAWhB,KAAA,GAEhBsB,KAAA,KAAU,UAAUN,UAAA,CAAWf,IAAA,GAC1Be,UAAA,CAAWf,IAAA,GAEbe,UAAA,CAAWjB,OAAA;AACpB;AAYO,SAASwB,2BACdP,UAAA,EACAQ,UAAA,EACAX,IAAA,EACAP,gBAAA,EACuB;EACvB,MAAMmB,MAAA,GAAS,mBAAIC,GAAA,CAAsB;EAEzC,WAAW/B,GAAA,IAAOkB,IAAA,EAAM;IACtB,MAAMc,aAAA,GAAgBX,UAAA,CAAWb,UAAA,CAAWR,GAAG;IAC/C,IAAIiC,cAAA,GAA2B;IAE3B,OAAOD,aAAA,IAAkB,WAC3BC,cAAA,GAAiBJ,UAAA,CAAWG,aAAa,KAAK,OAE9CA,aAAA,IACA,OAAOA,aAAA,IAAkB,YACxBA,aAAA,CAAsBE,IAAA,KAEvBD,cAAA,GAAiBJ,UAAA,CAAYG,aAAA,CAAsBE,IAAI,KAAK,OAI1DD,cAAA,KAAmB,SACrBA,cAAA,GAAiBtB,gBAAA,GAGnBmB,MAAA,CAAOK,GAAA,CAAInC,GAAA,EAAKiC,cAAc;EAChC;EAEA,OAAOH,MAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
|
|
4
|
+
return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
5
|
+
}
|
|
6
|
+
var SPRING_CONFIG_KEYS = /* @__PURE__ */new Set(["stiffness", "damping", "mass", "tension", "friction", "velocity", "overshootClamping", "duration", "bounciness", "speed"]);
|
|
7
|
+
function isSpringConfigKey(key) {
|
|
8
|
+
return SPRING_CONFIG_KEYS.has(key);
|
|
9
|
+
}
|
|
10
|
+
function normalizeTransition(transition) {
|
|
11
|
+
if (!transition) return {
|
|
12
|
+
default: null,
|
|
13
|
+
enter: null,
|
|
14
|
+
exit: null,
|
|
15
|
+
delay: void 0,
|
|
16
|
+
properties: {}
|
|
17
|
+
};
|
|
18
|
+
if (typeof transition == "string") return {
|
|
19
|
+
default: transition,
|
|
20
|
+
enter: null,
|
|
21
|
+
exit: null,
|
|
22
|
+
delay: void 0,
|
|
23
|
+
properties: {}
|
|
24
|
+
};
|
|
25
|
+
if (Array.isArray(transition)) {
|
|
26
|
+
var [defaultAnimation, configObj] = transition,
|
|
27
|
+
properties = {},
|
|
28
|
+
springConfig = {},
|
|
29
|
+
delay,
|
|
30
|
+
enter = null,
|
|
31
|
+
exit = null;
|
|
32
|
+
if (configObj && (typeof configObj > "u" ? "undefined" : _type_of(configObj)) === "object") {
|
|
33
|
+
var _iteratorNormalCompletion = !0,
|
|
34
|
+
_didIteratorError = !1,
|
|
35
|
+
_iteratorError = void 0;
|
|
36
|
+
try {
|
|
37
|
+
for (var _iterator = Object.entries(configObj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
38
|
+
var [key, value] = _step.value;
|
|
39
|
+
key === "delay" && typeof value == "number" ? delay = value : key === "enter" && typeof value == "string" ? enter = value : key === "exit" && typeof value == "string" ? exit = value : isSpringConfigKey(key) && value !== void 0 ? springConfig[key] = value : value !== void 0 && (properties[key] = value);
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
43
|
+
} finally {
|
|
44
|
+
try {
|
|
45
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
46
|
+
} finally {
|
|
47
|
+
if (_didIteratorError) throw _iteratorError;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
default: defaultAnimation,
|
|
53
|
+
enter,
|
|
54
|
+
exit,
|
|
55
|
+
delay,
|
|
56
|
+
properties,
|
|
57
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : void 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if ((typeof transition > "u" ? "undefined" : _type_of(transition)) === "object") {
|
|
61
|
+
var properties1 = {},
|
|
62
|
+
springConfig1 = {},
|
|
63
|
+
defaultAnimation1 = null,
|
|
64
|
+
enter1 = null,
|
|
65
|
+
exit1 = null,
|
|
66
|
+
delay1,
|
|
67
|
+
_iteratorNormalCompletion1 = !0,
|
|
68
|
+
_didIteratorError1 = !1,
|
|
69
|
+
_iteratorError1 = void 0;
|
|
70
|
+
try {
|
|
71
|
+
for (var _iterator1 = Object.entries(transition)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
|
|
72
|
+
var [key1, value1] = _step1.value;
|
|
73
|
+
key1 === "default" && typeof value1 == "string" ? defaultAnimation1 = value1 : key1 === "enter" && typeof value1 == "string" ? enter1 = value1 : key1 === "exit" && typeof value1 == "string" ? exit1 = value1 : key1 === "delay" && typeof value1 == "number" ? delay1 = value1 : isSpringConfigKey(key1) && value1 !== void 0 ? springConfig1[key1] = value1 : value1 !== void 0 && (properties1[key1] = value1);
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
_didIteratorError1 = !0, _iteratorError1 = err;
|
|
77
|
+
} finally {
|
|
78
|
+
try {
|
|
79
|
+
!_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
|
|
80
|
+
} finally {
|
|
81
|
+
if (_didIteratorError1) throw _iteratorError1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
default: defaultAnimation1,
|
|
86
|
+
enter: enter1,
|
|
87
|
+
exit: exit1,
|
|
88
|
+
delay: delay1,
|
|
89
|
+
properties: properties1,
|
|
90
|
+
config: Object.keys(springConfig1).length > 0 ? springConfig1 : void 0
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
default: null,
|
|
95
|
+
enter: null,
|
|
96
|
+
exit: null,
|
|
97
|
+
delay: void 0,
|
|
98
|
+
properties: {}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function getAnimationForProperty(normalized, property) {
|
|
102
|
+
var propertyAnimation = normalized.properties[property];
|
|
103
|
+
return propertyAnimation !== void 0 ? propertyAnimation : normalized.default;
|
|
104
|
+
}
|
|
105
|
+
function hasAnimation(normalized) {
|
|
106
|
+
return normalized.default !== null || normalized.enter !== null || normalized.exit !== null || Object.keys(normalized.properties).length > 0;
|
|
107
|
+
}
|
|
108
|
+
function getAnimatedProperties(normalized) {
|
|
109
|
+
return Object.keys(normalized.properties);
|
|
110
|
+
}
|
|
111
|
+
function getEffectiveAnimation(normalized, state) {
|
|
112
|
+
return state === "enter" && normalized.enter ? normalized.enter : state === "exit" && normalized.exit ? normalized.exit : normalized.default;
|
|
113
|
+
}
|
|
114
|
+
function getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation) {
|
|
115
|
+
var result = /* @__PURE__ */new Map(),
|
|
116
|
+
_iteratorNormalCompletion = !0,
|
|
117
|
+
_didIteratorError = !1,
|
|
118
|
+
_iteratorError = void 0;
|
|
119
|
+
try {
|
|
120
|
+
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
121
|
+
var key = _step.value,
|
|
122
|
+
propAnimation = normalized.properties[key],
|
|
123
|
+
animationValue = null;
|
|
124
|
+
if (typeof propAnimation == "string") {
|
|
125
|
+
var _animations_propAnimation;
|
|
126
|
+
animationValue = (_animations_propAnimation = animations[propAnimation]) !== null && _animations_propAnimation !== void 0 ? _animations_propAnimation : null;
|
|
127
|
+
} else if (propAnimation && (typeof propAnimation > "u" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type) {
|
|
128
|
+
var _animations_propAnimation_type;
|
|
129
|
+
animationValue = (_animations_propAnimation_type = animations[propAnimation.type]) !== null && _animations_propAnimation_type !== void 0 ? _animations_propAnimation_type : null;
|
|
130
|
+
}
|
|
131
|
+
animationValue === null && (animationValue = defaultAnimation), result.set(key, animationValue);
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
135
|
+
} finally {
|
|
136
|
+
try {
|
|
137
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
138
|
+
} finally {
|
|
139
|
+
if (_didIteratorError) throw _iteratorError;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
export { getAnimatedProperties, getAnimationConfigsForKeys, getAnimationForProperty, getEffectiveAnimation, hasAnimation, normalizeTransition };
|
|
145
|
+
//# sourceMappingURL=normalizeTransition.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_type_of","obj","Symbol","constructor","SPRING_CONFIG_KEYS","Set","isSpringConfigKey","key","has","normalizeTransition","transition","default","enter","exit","delay","properties","Array","isArray","defaultAnimation","configObj","springConfig","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Object","entries","iterator","_step","next","done","value","err","return","config","keys","length","properties1","springConfig1","defaultAnimation1","enter1","exit1","delay1","_iteratorNormalCompletion1","_didIteratorError1","_iteratorError1","_iterator1","_step1","key1","value1"],"sources":["../../src/normalizeTransition.ts"],"sourcesContent":[null],"mappings":"AAOA,SAAMA,SAAAC,GAAA;EACJ;;EACA,OAAAA,GAAA,WAAAC,MAAA,UAAAD,GAAA,CAAAE,WAAA,KAAAD,MAAA,qBAAAD,GAAA;AA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A,MAAA,gBAAAZ,WAAA,CAAAW,IAAA,IAAAC,MAAA;MACxD;IAMF,SAAAjB,GAAA;MAKOY,kBAAsB,OAAAC,eAA2C,GAAAb,GAAA;IACtE,UACE;MAKJ;QAMO,CAASW,0BAAsB,IAAAG,UAA4C,CAAAb,MAAA,YAAAa,UAAA,CAAAb,MAAA;MAChF,UAAc;QAChB,IAAAW,kBAAA,EAUgB,MAAAC,eACd;MAGA;IAOF;IAYO,OAAS;MAMdlC,OAAM,EAAA4B,iBAAS;MAEf3B,KAAA,EAAW4B,MAAA;MACT3B,IAAM,EAAA4B,KAAA;MACN3B,KAAI,EAAA4B,MAAA;MAEA3B,UAAO,EAAAsB,WAAkB;MAgB/BH,MAAA,EAAAT,MAAA,CAAAU,IAAA,CAAAG,aAAA,EAAAF,MAAA,OAAAE,aAAA;IAEA;EACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/animation-helpers",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"source": "src/index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"types",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "dist/cjs",
|
|
15
|
+
"module": "dist/esm",
|
|
16
|
+
"types": "./types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"react-native": "./dist/esm/index.native.js",
|
|
22
|
+
"browser": "./dist/esm/index.mjs",
|
|
23
|
+
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"import": "./dist/esm/index.mjs",
|
|
25
|
+
"require": "./dist/cjs/index.cjs",
|
|
26
|
+
"default": "./dist/esm/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "hanzo-gui-build",
|
|
34
|
+
"watch": "hanzo-gui-build --watch",
|
|
35
|
+
"clean": "hanzo-gui-build clean",
|
|
36
|
+
"clean:build": "hanzo-gui-build clean:build"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@hanzogui/build": "workspace:*"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export {
|
|
2
|
+
normalizeTransition,
|
|
3
|
+
getAnimationForProperty,
|
|
4
|
+
hasAnimation,
|
|
5
|
+
getAnimatedProperties,
|
|
6
|
+
getEffectiveAnimation,
|
|
7
|
+
getAnimationConfigsForKeys,
|
|
8
|
+
} from './normalizeTransition'
|
|
9
|
+
|
|
10
|
+
export type { AnimationConfig, NormalizedTransition, TransitionPropInput } from './types'
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnimationConfig,
|
|
3
|
+
NormalizedTransition,
|
|
4
|
+
SpringConfig,
|
|
5
|
+
TransitionPropInput,
|
|
6
|
+
} from './types'
|
|
7
|
+
|
|
8
|
+
const SPRING_CONFIG_KEYS: Set<string> = new Set([
|
|
9
|
+
'stiffness',
|
|
10
|
+
'damping',
|
|
11
|
+
'mass',
|
|
12
|
+
'tension',
|
|
13
|
+
'friction',
|
|
14
|
+
'velocity',
|
|
15
|
+
'overshootClamping',
|
|
16
|
+
'duration',
|
|
17
|
+
'bounciness',
|
|
18
|
+
'speed',
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check if a key is a spring config parameter
|
|
23
|
+
*/
|
|
24
|
+
function isSpringConfigKey(key: string): key is keyof SpringConfig {
|
|
25
|
+
return SPRING_CONFIG_KEYS.has(key)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Normalizes the various transition prop formats into a consistent structure.
|
|
30
|
+
*
|
|
31
|
+
* Supported input formats:
|
|
32
|
+
* - String: "bouncy" -> { default: "bouncy", enter: null, exit: null, properties: {} }
|
|
33
|
+
* - Object: { x: 'quick', default: 'slow' } -> { default: "slow", enter: null, exit: null, properties: { x: "quick" } }
|
|
34
|
+
* - Object with enter/exit: { enter: 'bouncy', exit: 'quick' } -> { default: null, enter: "bouncy", exit: "quick", properties: {} }
|
|
35
|
+
* - Array: ['bouncy', { delay: 100, x: 'quick' }] -> { default: "bouncy", enter: null, exit: null, delay: 100, properties: { x: "quick" } }
|
|
36
|
+
*
|
|
37
|
+
* @param transition - The transition prop value in any supported format
|
|
38
|
+
* @returns Normalized transition object with consistent structure
|
|
39
|
+
*/
|
|
40
|
+
export function normalizeTransition(
|
|
41
|
+
transition: TransitionPropInput
|
|
42
|
+
): NormalizedTransition {
|
|
43
|
+
// Handle null/undefined
|
|
44
|
+
if (!transition) {
|
|
45
|
+
return {
|
|
46
|
+
default: null,
|
|
47
|
+
enter: null,
|
|
48
|
+
exit: null,
|
|
49
|
+
delay: undefined,
|
|
50
|
+
properties: {},
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// String format: "bouncy"
|
|
55
|
+
if (typeof transition === 'string') {
|
|
56
|
+
return {
|
|
57
|
+
default: transition,
|
|
58
|
+
enter: null,
|
|
59
|
+
exit: null,
|
|
60
|
+
delay: undefined,
|
|
61
|
+
properties: {},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Array format: ['bouncy', { delay: 100, x: 'quick', enter: 'slow', exit: 'fast' }]
|
|
66
|
+
// Also supports spring config overrides: ['bouncy', { stiffness: 1000, damping: 70 }]
|
|
67
|
+
if (Array.isArray(transition)) {
|
|
68
|
+
const [defaultAnimation, configObj] = transition
|
|
69
|
+
const properties: Record<string, string | AnimationConfig> = {}
|
|
70
|
+
const springConfig: SpringConfig = {}
|
|
71
|
+
let delay: number | undefined
|
|
72
|
+
let enter: string | null = null
|
|
73
|
+
let exit: string | null = null
|
|
74
|
+
|
|
75
|
+
if (configObj && typeof configObj === 'object') {
|
|
76
|
+
for (const [key, value] of Object.entries(configObj)) {
|
|
77
|
+
if (key === 'delay' && typeof value === 'number') {
|
|
78
|
+
delay = value
|
|
79
|
+
} else if (key === 'enter' && typeof value === 'string') {
|
|
80
|
+
enter = value
|
|
81
|
+
} else if (key === 'exit' && typeof value === 'string') {
|
|
82
|
+
exit = value
|
|
83
|
+
} else if (isSpringConfigKey(key) && value !== undefined) {
|
|
84
|
+
// Spring config override: { stiffness: 1000, damping: 70 }
|
|
85
|
+
springConfig[key] = value as SpringConfig[keyof SpringConfig]
|
|
86
|
+
} else if (value !== undefined) {
|
|
87
|
+
// Property-specific animation: string or config object
|
|
88
|
+
properties[key] = value as string | AnimationConfig
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
default: defaultAnimation,
|
|
95
|
+
enter,
|
|
96
|
+
exit,
|
|
97
|
+
delay,
|
|
98
|
+
properties,
|
|
99
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : undefined,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Object format: { x: 'quick', y: 'bouncy', default: 'slow', enter: 'bouncy', exit: 'quick' }
|
|
104
|
+
// Also supports spring config overrides: { default: 'bouncy', stiffness: 1000 }
|
|
105
|
+
if (typeof transition === 'object') {
|
|
106
|
+
const properties: Record<string, string | AnimationConfig> = {}
|
|
107
|
+
const springConfig: SpringConfig = {}
|
|
108
|
+
let defaultAnimation: string | null = null
|
|
109
|
+
let enter: string | null = null
|
|
110
|
+
let exit: string | null = null
|
|
111
|
+
let delay: number | undefined
|
|
112
|
+
|
|
113
|
+
for (const [key, value] of Object.entries(transition)) {
|
|
114
|
+
if (key === 'default' && typeof value === 'string') {
|
|
115
|
+
defaultAnimation = value
|
|
116
|
+
} else if (key === 'enter' && typeof value === 'string') {
|
|
117
|
+
enter = value
|
|
118
|
+
} else if (key === 'exit' && typeof value === 'string') {
|
|
119
|
+
exit = value
|
|
120
|
+
} else if (key === 'delay' && typeof value === 'number') {
|
|
121
|
+
delay = value
|
|
122
|
+
} else if (isSpringConfigKey(key) && value !== undefined) {
|
|
123
|
+
// Spring config override: { stiffness: 1000, damping: 70 }
|
|
124
|
+
springConfig[key] = value as SpringConfig[keyof SpringConfig]
|
|
125
|
+
} else if (value !== undefined) {
|
|
126
|
+
// Property-specific animation: string or config object
|
|
127
|
+
properties[key] = value as string | AnimationConfig
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
default: defaultAnimation,
|
|
133
|
+
enter,
|
|
134
|
+
exit,
|
|
135
|
+
delay,
|
|
136
|
+
properties,
|
|
137
|
+
config: Object.keys(springConfig).length > 0 ? springConfig : undefined,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Fallback
|
|
142
|
+
return {
|
|
143
|
+
default: null,
|
|
144
|
+
enter: null,
|
|
145
|
+
exit: null,
|
|
146
|
+
delay: undefined,
|
|
147
|
+
properties: {},
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Gets the animation key for a specific property from a normalized transition.
|
|
153
|
+
* Falls back to the default animation if no property-specific one is defined.
|
|
154
|
+
*
|
|
155
|
+
* @param normalized - The normalized transition object
|
|
156
|
+
* @param property - The property name to get animation for (e.g., 'x', 'opacity')
|
|
157
|
+
* @returns The animation key/config or null if none defined
|
|
158
|
+
*/
|
|
159
|
+
export function getAnimationForProperty(
|
|
160
|
+
normalized: NormalizedTransition,
|
|
161
|
+
property: string
|
|
162
|
+
): string | AnimationConfig | null {
|
|
163
|
+
// Check for property-specific animation
|
|
164
|
+
const propertyAnimation = normalized.properties[property]
|
|
165
|
+
if (propertyAnimation !== undefined) {
|
|
166
|
+
return propertyAnimation
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Fall back to default
|
|
170
|
+
return normalized.default
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Checks if the normalized transition has any animations defined.
|
|
175
|
+
*/
|
|
176
|
+
export function hasAnimation(normalized: NormalizedTransition): boolean {
|
|
177
|
+
return (
|
|
178
|
+
normalized.default !== null ||
|
|
179
|
+
normalized.enter !== null ||
|
|
180
|
+
normalized.exit !== null ||
|
|
181
|
+
Object.keys(normalized.properties).length > 0
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Gets all property names that have specific animations defined.
|
|
187
|
+
* Does not include 'default' in the list.
|
|
188
|
+
*/
|
|
189
|
+
export function getAnimatedProperties(normalized: NormalizedTransition): string[] {
|
|
190
|
+
return Object.keys(normalized.properties)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Gets the effective animation key based on the current animation state.
|
|
195
|
+
* Priority: enter/exit specific > default > null
|
|
196
|
+
*
|
|
197
|
+
* @param normalized - The normalized transition object
|
|
198
|
+
* @param state - The animation state: 'enter', 'exit', or 'default'
|
|
199
|
+
* @returns The effective animation key or null
|
|
200
|
+
*/
|
|
201
|
+
export function getEffectiveAnimation(
|
|
202
|
+
normalized: NormalizedTransition,
|
|
203
|
+
state: 'enter' | 'exit' | 'default'
|
|
204
|
+
): string | null {
|
|
205
|
+
if (state === 'enter' && normalized.enter) {
|
|
206
|
+
return normalized.enter
|
|
207
|
+
}
|
|
208
|
+
if (state === 'exit' && normalized.exit) {
|
|
209
|
+
return normalized.exit
|
|
210
|
+
}
|
|
211
|
+
return normalized.default
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Gets the resolved animation config for each key, looking up in animations config.
|
|
216
|
+
* Useful for calculating max duration across all animated properties.
|
|
217
|
+
*
|
|
218
|
+
* @param normalized - The normalized transition object
|
|
219
|
+
* @param animations - The animations config object (driver-specific format)
|
|
220
|
+
* @param keys - Property keys to get animations for
|
|
221
|
+
* @param defaultAnimation - The default animation value to fall back to
|
|
222
|
+
* @returns Map of key -> resolved animation config (or null if not found)
|
|
223
|
+
*/
|
|
224
|
+
export function getAnimationConfigsForKeys<T>(
|
|
225
|
+
normalized: NormalizedTransition,
|
|
226
|
+
animations: Record<string, T>,
|
|
227
|
+
keys: string[],
|
|
228
|
+
defaultAnimation: T | null
|
|
229
|
+
): Map<string, T | null> {
|
|
230
|
+
const result = new Map<string, T | null>()
|
|
231
|
+
|
|
232
|
+
for (const key of keys) {
|
|
233
|
+
const propAnimation = normalized.properties[key]
|
|
234
|
+
let animationValue: T | null = null
|
|
235
|
+
|
|
236
|
+
if (typeof propAnimation === 'string') {
|
|
237
|
+
animationValue = animations[propAnimation] ?? null
|
|
238
|
+
} else if (
|
|
239
|
+
propAnimation &&
|
|
240
|
+
typeof propAnimation === 'object' &&
|
|
241
|
+
(propAnimation as any).type
|
|
242
|
+
) {
|
|
243
|
+
animationValue = animations[(propAnimation as any).type] ?? null
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// fall back to default if no per-property config found
|
|
247
|
+
if (animationValue === null) {
|
|
248
|
+
animationValue = defaultAnimation
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
result.set(key, animationValue)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return result
|
|
255
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation configuration that can include additional properties
|
|
3
|
+
* like delay, duration, stiffness, damping, etc.
|
|
4
|
+
*/
|
|
5
|
+
export type AnimationConfig = {
|
|
6
|
+
type?: string
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Input format for the transition prop - supports multiple syntaxes:
|
|
12
|
+
*
|
|
13
|
+
* 1. String: "bouncy"
|
|
14
|
+
* 2. Object with property mappings: { x: 'quick', y: 'bouncy', default: 'slow' }
|
|
15
|
+
* 3. Array with config: ['bouncy', { delay: 100, x: 'quick' }]
|
|
16
|
+
* 4. Object with enter/exit: { enter: 'bouncy', exit: 'quick', default: 'slow' }
|
|
17
|
+
*
|
|
18
|
+
* Note: Uses `any` to be compatible with the TransitionProp type from @hanzogui/web
|
|
19
|
+
* which has more complex union types.
|
|
20
|
+
*/
|
|
21
|
+
export type TransitionPropInput = any
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Spring configuration parameters that can override preset defaults.
|
|
25
|
+
* These are the common parameters across animation drivers.
|
|
26
|
+
*/
|
|
27
|
+
export type SpringConfig = {
|
|
28
|
+
stiffness?: number
|
|
29
|
+
damping?: number
|
|
30
|
+
mass?: number
|
|
31
|
+
tension?: number
|
|
32
|
+
friction?: number
|
|
33
|
+
velocity?: number
|
|
34
|
+
overshootClamping?: boolean
|
|
35
|
+
duration?: number
|
|
36
|
+
bounciness?: number
|
|
37
|
+
speed?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Normalized output format that all animation drivers consume.
|
|
42
|
+
* Provides a consistent structure regardless of input format.
|
|
43
|
+
*/
|
|
44
|
+
export type NormalizedTransition = {
|
|
45
|
+
/** Default animation key for properties not explicitly listed */
|
|
46
|
+
default: string | null
|
|
47
|
+
/** Animation key to use during enter transitions (mount) */
|
|
48
|
+
enter: string | null
|
|
49
|
+
/** Animation key to use during exit transitions (unmount) */
|
|
50
|
+
exit: string | null
|
|
51
|
+
/** Global delay in ms */
|
|
52
|
+
delay: number | undefined
|
|
53
|
+
/** Per-property animation configs: propertyName -> animationKey or config */
|
|
54
|
+
properties: Record<string, string | AnimationConfig>
|
|
55
|
+
/** Global spring config overrides that merge with the preset defaults */
|
|
56
|
+
config?: SpringConfig
|
|
57
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { normalizeTransition, getAnimationForProperty, hasAnimation, getAnimatedProperties, getEffectiveAnimation, getAnimationConfigsForKeys } from "./normalizeTransition";
|
|
2
|
+
export type { AnimationConfig, NormalizedTransition, TransitionPropInput } from "./types";
|
|
3
|
+
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,SACE,qBACA,yBACA,cACA,uBACA,uBACA,kCACK;AAEP,cAAc,iBAAiB,sBAAsB,2BAA2B",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/index.ts"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"export {\n normalizeTransition,\n getAnimationForProperty,\n hasAnimation,\n getAnimatedProperties,\n getEffectiveAnimation,\n getAnimationConfigsForKeys,\n} from './normalizeTransition'\n\nexport type { AnimationConfig, NormalizedTransition, TransitionPropInput } from './types'\n"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AnimationConfig, NormalizedTransition, TransitionPropInput } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes the various transition prop formats into a consistent structure.
|
|
4
|
+
*
|
|
5
|
+
* Supported input formats:
|
|
6
|
+
* - String: "bouncy" -> { default: "bouncy", enter: null, exit: null, properties: {} }
|
|
7
|
+
* - Object: { x: 'quick', default: 'slow' } -> { default: "slow", enter: null, exit: null, properties: { x: "quick" } }
|
|
8
|
+
* - Object with enter/exit: { enter: 'bouncy', exit: 'quick' } -> { default: null, enter: "bouncy", exit: "quick", properties: {} }
|
|
9
|
+
* - Array: ['bouncy', { delay: 100, x: 'quick' }] -> { default: "bouncy", enter: null, exit: null, delay: 100, properties: { x: "quick" } }
|
|
10
|
+
*
|
|
11
|
+
* @param transition - The transition prop value in any supported format
|
|
12
|
+
* @returns Normalized transition object with consistent structure
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeTransition(transition: TransitionPropInput): NormalizedTransition;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the animation key for a specific property from a normalized transition.
|
|
17
|
+
* Falls back to the default animation if no property-specific one is defined.
|
|
18
|
+
*
|
|
19
|
+
* @param normalized - The normalized transition object
|
|
20
|
+
* @param property - The property name to get animation for (e.g., 'x', 'opacity')
|
|
21
|
+
* @returns The animation key/config or null if none defined
|
|
22
|
+
*/
|
|
23
|
+
export declare function getAnimationForProperty(normalized: NormalizedTransition, property: string): string | AnimationConfig | null;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the normalized transition has any animations defined.
|
|
26
|
+
*/
|
|
27
|
+
export declare function hasAnimation(normalized: NormalizedTransition): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Gets all property names that have specific animations defined.
|
|
30
|
+
* Does not include 'default' in the list.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAnimatedProperties(normalized: NormalizedTransition): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Gets the effective animation key based on the current animation state.
|
|
35
|
+
* Priority: enter/exit specific > default > null
|
|
36
|
+
*
|
|
37
|
+
* @param normalized - The normalized transition object
|
|
38
|
+
* @param state - The animation state: 'enter', 'exit', or 'default'
|
|
39
|
+
* @returns The effective animation key or null
|
|
40
|
+
*/
|
|
41
|
+
export declare function getEffectiveAnimation(normalized: NormalizedTransition, state: "enter" | "exit" | "default"): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the resolved animation config for each key, looking up in animations config.
|
|
44
|
+
* Useful for calculating max duration across all animated properties.
|
|
45
|
+
*
|
|
46
|
+
* @param normalized - The normalized transition object
|
|
47
|
+
* @param animations - The animations config object (driver-specific format)
|
|
48
|
+
* @param keys - Property keys to get animations for
|
|
49
|
+
* @param defaultAnimation - The default animation value to fall back to
|
|
50
|
+
* @returns Map of key -> resolved animation config (or null if not found)
|
|
51
|
+
*/
|
|
52
|
+
export declare function getAnimationConfigsForKeys<T>(normalized: NormalizedTransition, animations: Record<string, T>, keys: string[], defaultAnimation: T | null): Map<string, T | null>;
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=normalizeTransition.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cACE,iBACA,sBAEA,2BACK;;;;;;;;;;;;;AAkCP,OAAO,iBAAS,oBACd,YAAY,sBACX;;;;;;;;;AAqHH,OAAO,iBAAS,wBACd,YAAY,sBACZ,4BACU;;;;AAcZ,OAAO,iBAAS,aAAa,YAAY;;;;;AAazC,OAAO,iBAAS,sBAAsB,YAAY;;;;;;;;;AAYlD,OAAO,iBAAS,sBACd,YAAY,sBACZ,OAAO,UAAU,SAAS;;;;;;;;;;;AAqB5B,OAAO,iBAAS,2BAA2B,GACzC,YAAY,sBACZ,YAAY,eAAe,IAC3B,gBACA,kBAAkB,WACjB,YAAY",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/normalizeTransition.ts"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"import type {\n AnimationConfig,\n NormalizedTransition,\n SpringConfig,\n TransitionPropInput,\n} from './types'\n\nconst SPRING_CONFIG_KEYS: Set<string> = new Set([\n 'stiffness',\n 'damping',\n 'mass',\n 'tension',\n 'friction',\n 'velocity',\n 'overshootClamping',\n 'duration',\n 'bounciness',\n 'speed',\n])\n\n/**\n * Check if a key is a spring config parameter\n */\nfunction isSpringConfigKey(key: string): key is keyof SpringConfig {\n return SPRING_CONFIG_KEYS.has(key)\n}\n\n/**\n * Normalizes the various transition prop formats into a consistent structure.\n *\n * Supported input formats:\n * - String: \"bouncy\" -> { default: \"bouncy\", enter: null, exit: null, properties: {} }\n * - Object: { x: 'quick', default: 'slow' } -> { default: \"slow\", enter: null, exit: null, properties: { x: \"quick\" } }\n * - Object with enter/exit: { enter: 'bouncy', exit: 'quick' } -> { default: null, enter: \"bouncy\", exit: \"quick\", properties: {} }\n * - Array: ['bouncy', { delay: 100, x: 'quick' }] -> { default: \"bouncy\", enter: null, exit: null, delay: 100, properties: { x: \"quick\" } }\n *\n * @param transition - The transition prop value in any supported format\n * @returns Normalized transition object with consistent structure\n */\nexport function normalizeTransition(\n transition: TransitionPropInput\n): NormalizedTransition {\n // Handle null/undefined\n if (!transition) {\n return {\n default: null,\n enter: null,\n exit: null,\n delay: undefined,\n properties: {},\n }\n }\n\n // String format: \"bouncy\"\n if (typeof transition === 'string') {\n return {\n default: transition,\n enter: null,\n exit: null,\n delay: undefined,\n properties: {},\n }\n }\n\n // Array format: ['bouncy', { delay: 100, x: 'quick', enter: 'slow', exit: 'fast' }]\n // Also supports spring config overrides: ['bouncy', { stiffness: 1000, damping: 70 }]\n if (Array.isArray(transition)) {\n const [defaultAnimation, configObj] = transition\n const properties: Record<string, string | AnimationConfig> = {}\n const springConfig: SpringConfig = {}\n let delay: number | undefined\n let enter: string | null = null\n let exit: string | null = null\n\n if (configObj && typeof configObj === 'object') {\n for (const [key, value] of Object.entries(configObj)) {\n if (key === 'delay' && typeof value === 'number') {\n delay = value\n } else if (key === 'enter' && typeof value === 'string') {\n enter = value\n } else if (key === 'exit' && typeof value === 'string') {\n exit = value\n } else if (isSpringConfigKey(key) && value !== undefined) {\n // Spring config override: { stiffness: 1000, damping: 70 }\n springConfig[key] = value as SpringConfig[keyof SpringConfig]\n } else if (value !== undefined) {\n // Property-specific animation: string or config object\n properties[key] = value as string | AnimationConfig\n }\n }\n }\n\n return {\n default: defaultAnimation,\n enter,\n exit,\n delay,\n properties,\n config: Object.keys(springConfig).length > 0 ? springConfig : undefined,\n }\n }\n\n // Object format: { x: 'quick', y: 'bouncy', default: 'slow', enter: 'bouncy', exit: 'quick' }\n // Also supports spring config overrides: { default: 'bouncy', stiffness: 1000 }\n if (typeof transition === 'object') {\n const properties: Record<string, string | AnimationConfig> = {}\n const springConfig: SpringConfig = {}\n let defaultAnimation: string | null = null\n let enter: string | null = null\n let exit: string | null = null\n let delay: number | undefined\n\n for (const [key, value] of Object.entries(transition)) {\n if (key === 'default' && typeof value === 'string') {\n defaultAnimation = value\n } else if (key === 'enter' && typeof value === 'string') {\n enter = value\n } else if (key === 'exit' && typeof value === 'string') {\n exit = value\n } else if (key === 'delay' && typeof value === 'number') {\n delay = value\n } else if (isSpringConfigKey(key) && value !== undefined) {\n // Spring config override: { stiffness: 1000, damping: 70 }\n springConfig[key] = value as SpringConfig[keyof SpringConfig]\n } else if (value !== undefined) {\n // Property-specific animation: string or config object\n properties[key] = value as string | AnimationConfig\n }\n }\n\n return {\n default: defaultAnimation,\n enter,\n exit,\n delay,\n properties,\n config: Object.keys(springConfig).length > 0 ? springConfig : undefined,\n }\n }\n\n // Fallback\n return {\n default: null,\n enter: null,\n exit: null,\n delay: undefined,\n properties: {},\n }\n}\n\n/**\n * Gets the animation key for a specific property from a normalized transition.\n * Falls back to the default animation if no property-specific one is defined.\n *\n * @param normalized - The normalized transition object\n * @param property - The property name to get animation for (e.g., 'x', 'opacity')\n * @returns The animation key/config or null if none defined\n */\nexport function getAnimationForProperty(\n normalized: NormalizedTransition,\n property: string\n): string | AnimationConfig | null {\n // Check for property-specific animation\n const propertyAnimation = normalized.properties[property]\n if (propertyAnimation !== undefined) {\n return propertyAnimation\n }\n\n // Fall back to default\n return normalized.default\n}\n\n/**\n * Checks if the normalized transition has any animations defined.\n */\nexport function hasAnimation(normalized: NormalizedTransition): boolean {\n return (\n normalized.default !== null ||\n normalized.enter !== null ||\n normalized.exit !== null ||\n Object.keys(normalized.properties).length > 0\n )\n}\n\n/**\n * Gets all property names that have specific animations defined.\n * Does not include 'default' in the list.\n */\nexport function getAnimatedProperties(normalized: NormalizedTransition): string[] {\n return Object.keys(normalized.properties)\n}\n\n/**\n * Gets the effective animation key based on the current animation state.\n * Priority: enter/exit specific > default > null\n *\n * @param normalized - The normalized transition object\n * @param state - The animation state: 'enter', 'exit', or 'default'\n * @returns The effective animation key or null\n */\nexport function getEffectiveAnimation(\n normalized: NormalizedTransition,\n state: 'enter' | 'exit' | 'default'\n): string | null {\n if (state === 'enter' && normalized.enter) {\n return normalized.enter\n }\n if (state === 'exit' && normalized.exit) {\n return normalized.exit\n }\n return normalized.default\n}\n\n/**\n * Gets the resolved animation config for each key, looking up in animations config.\n * Useful for calculating max duration across all animated properties.\n *\n * @param normalized - The normalized transition object\n * @param animations - The animations config object (driver-specific format)\n * @param keys - Property keys to get animations for\n * @param defaultAnimation - The default animation value to fall back to\n * @returns Map of key -> resolved animation config (or null if not found)\n */\nexport function getAnimationConfigsForKeys<T>(\n normalized: NormalizedTransition,\n animations: Record<string, T>,\n keys: string[],\n defaultAnimation: T | null\n): Map<string, T | null> {\n const result = new Map<string, T | null>()\n\n for (const key of keys) {\n const propAnimation = normalized.properties[key]\n let animationValue: T | null = null\n\n if (typeof propAnimation === 'string') {\n animationValue = animations[propAnimation] ?? null\n } else if (\n propAnimation &&\n typeof propAnimation === 'object' &&\n (propAnimation as any).type\n ) {\n animationValue = animations[(propAnimation as any).type] ?? null\n }\n\n // fall back to default if no per-property config found\n if (animationValue === null) {\n animationValue = defaultAnimation\n }\n\n result.set(key, animationValue)\n }\n\n return result\n}\n"
|
|
10
|
+
]
|
|
11
|
+
}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation configuration that can include additional properties
|
|
3
|
+
* like delay, duration, stiffness, damping, etc.
|
|
4
|
+
*/
|
|
5
|
+
export type AnimationConfig = {
|
|
6
|
+
type?: string;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Input format for the transition prop - supports multiple syntaxes:
|
|
11
|
+
*
|
|
12
|
+
* 1. String: "bouncy"
|
|
13
|
+
* 2. Object with property mappings: { x: 'quick', y: 'bouncy', default: 'slow' }
|
|
14
|
+
* 3. Array with config: ['bouncy', { delay: 100, x: 'quick' }]
|
|
15
|
+
* 4. Object with enter/exit: { enter: 'bouncy', exit: 'quick', default: 'slow' }
|
|
16
|
+
*
|
|
17
|
+
* Note: Uses `any` to be compatible with the TransitionProp type from @hanzogui/web
|
|
18
|
+
* which has more complex union types.
|
|
19
|
+
*/
|
|
20
|
+
export type TransitionPropInput = any;
|
|
21
|
+
/**
|
|
22
|
+
* Spring configuration parameters that can override preset defaults.
|
|
23
|
+
* These are the common parameters across animation drivers.
|
|
24
|
+
*/
|
|
25
|
+
export type SpringConfig = {
|
|
26
|
+
stiffness?: number;
|
|
27
|
+
damping?: number;
|
|
28
|
+
mass?: number;
|
|
29
|
+
tension?: number;
|
|
30
|
+
friction?: number;
|
|
31
|
+
velocity?: number;
|
|
32
|
+
overshootClamping?: boolean;
|
|
33
|
+
duration?: number;
|
|
34
|
+
bounciness?: number;
|
|
35
|
+
speed?: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Normalized output format that all animation drivers consume.
|
|
39
|
+
* Provides a consistent structure regardless of input format.
|
|
40
|
+
*/
|
|
41
|
+
export type NormalizedTransition = {
|
|
42
|
+
/** Default animation key for properties not explicitly listed */
|
|
43
|
+
default: string | null;
|
|
44
|
+
/** Animation key to use during enter transitions (mount) */
|
|
45
|
+
enter: string | null;
|
|
46
|
+
/** Animation key to use during exit transitions (unmount) */
|
|
47
|
+
exit: string | null;
|
|
48
|
+
/** Global delay in ms */
|
|
49
|
+
delay: number | undefined;
|
|
50
|
+
/** Per-property animation configs: propertyName -> animationKey or config */
|
|
51
|
+
properties: Record<string, string | AnimationConfig>;
|
|
52
|
+
/** Global spring config overrides that merge with the preset defaults */
|
|
53
|
+
config?: SpringConfig;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": ";;;;AAIA,YAAY,kBAAkB;CAC5B;;;;;;;;;;;;;;AAeF,YAAY;;;;;AAMZ,YAAY,eAAe;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;AAOF,YAAY,uBAAuB;;CAEjC;;CAEA;;CAEA;;CAEA;;CAEA,YAAY,wBAAwB;;CAEpC,SAAS",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/types.ts"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"/**\n * Animation configuration that can include additional properties\n * like delay, duration, stiffness, damping, etc.\n */\nexport type AnimationConfig = {\n type?: string\n [key: string]: any\n}\n\n/**\n * Input format for the transition prop - supports multiple syntaxes:\n *\n * 1. String: \"bouncy\"\n * 2. Object with property mappings: { x: 'quick', y: 'bouncy', default: 'slow' }\n * 3. Array with config: ['bouncy', { delay: 100, x: 'quick' }]\n * 4. Object with enter/exit: { enter: 'bouncy', exit: 'quick', default: 'slow' }\n *\n * Note: Uses `any` to be compatible with the TransitionProp type from @hanzogui/web\n * which has more complex union types.\n */\nexport type TransitionPropInput = any\n\n/**\n * Spring configuration parameters that can override preset defaults.\n * These are the common parameters across animation drivers.\n */\nexport type SpringConfig = {\n stiffness?: number\n damping?: number\n mass?: number\n tension?: number\n friction?: number\n velocity?: number\n overshootClamping?: boolean\n duration?: number\n bounciness?: number\n speed?: number\n}\n\n/**\n * Normalized output format that all animation drivers consume.\n * Provides a consistent structure regardless of input format.\n */\nexport type NormalizedTransition = {\n /** Default animation key for properties not explicitly listed */\n default: string | null\n /** Animation key to use during enter transitions (mount) */\n enter: string | null\n /** Animation key to use during exit transitions (unmount) */\n exit: string | null\n /** Global delay in ms */\n delay: number | undefined\n /** Per-property animation configs: propertyName -> animationKey or config */\n properties: Record<string, string | AnimationConfig>\n /** Global spring config overrides that merge with the preset defaults */\n config?: SpringConfig\n}\n"
|
|
10
|
+
]
|
|
11
|
+
}
|