@tamagui/animation-helpers 2.7.7 → 3.0.0-beta.1093.1

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.
Files changed (79) hide show
  1. package/dist/cjs/index.cjs +32 -21
  2. package/dist/cjs/index.native.cjs +46 -0
  3. package/dist/cjs/index.native.js +33 -21
  4. package/dist/cjs/index.native.js.map +1 -1
  5. package/dist/cjs/presets.cjs +77 -0
  6. package/dist/cjs/presets.native.cjs +79 -0
  7. package/dist/cjs/presets.native.js +81 -0
  8. package/dist/cjs/presets.native.js.map +1 -0
  9. package/dist/cjs/propertyNames.cjs +91 -0
  10. package/dist/cjs/propertyNames.native.cjs +95 -0
  11. package/dist/cjs/propertyNames.native.js +97 -0
  12. package/dist/cjs/propertyNames.native.js.map +1 -0
  13. package/dist/cjs/resolveTransition.cjs +345 -0
  14. package/dist/cjs/resolveTransition.native.cjs +424 -0
  15. package/dist/cjs/resolveTransition.native.js +426 -0
  16. package/dist/cjs/resolveTransition.native.js.map +1 -0
  17. package/dist/cjs/transitionResolver.cjs +34 -0
  18. package/dist/cjs/transitionResolver.native.cjs +37 -0
  19. package/dist/cjs/transitionResolver.native.js +39 -0
  20. package/dist/cjs/transitionResolver.native.js.map +1 -0
  21. package/dist/cjs/types.cjs +9 -11
  22. package/dist/cjs/types.native.cjs +18 -0
  23. package/dist/cjs/types.native.js +9 -10
  24. package/dist/cjs/types.native.js.map +1 -1
  25. package/dist/esm/index.js +6 -3
  26. package/dist/esm/index.mjs +6 -3
  27. package/dist/esm/index.native.js +6 -3
  28. package/dist/esm/presets.mjs +57 -0
  29. package/dist/esm/presets.mjs.map +1 -0
  30. package/dist/esm/presets.native.js +57 -0
  31. package/dist/esm/presets.native.js.map +1 -0
  32. package/dist/esm/propertyNames.mjs +67 -0
  33. package/dist/esm/propertyNames.mjs.map +1 -0
  34. package/dist/esm/propertyNames.native.js +69 -0
  35. package/dist/esm/propertyNames.native.js.map +1 -0
  36. package/dist/esm/resolveTransition.mjs +315 -0
  37. package/dist/esm/resolveTransition.mjs.map +1 -0
  38. package/dist/esm/resolveTransition.native.js +392 -0
  39. package/dist/esm/resolveTransition.native.js.map +1 -0
  40. package/dist/esm/transitionResolver.mjs +11 -0
  41. package/dist/esm/transitionResolver.mjs.map +1 -0
  42. package/dist/esm/transitionResolver.native.js +12 -0
  43. package/dist/esm/transitionResolver.native.js.map +1 -0
  44. package/dist/esm/types.mjs +0 -2
  45. package/dist/esm/types.native.js +0 -2
  46. package/package.json +23 -2
  47. package/src/index.ts +39 -9
  48. package/src/presets.ts +40 -0
  49. package/src/propertyNames.ts +78 -0
  50. package/src/resolveTransition.ts +503 -0
  51. package/src/transitionResolver.ts +35 -0
  52. package/src/types.ts +42 -46
  53. package/types/index.d.ts +6 -2
  54. package/types/index.d.ts.map +2 -2
  55. package/types/presets.d.ts +79 -0
  56. package/types/presets.d.ts.map +11 -0
  57. package/types/propertyNames.d.ts +13 -0
  58. package/types/propertyNames.d.ts.map +11 -0
  59. package/types/resolveTransition.d.ts +108 -0
  60. package/types/resolveTransition.d.ts.map +11 -0
  61. package/types/transitionResolver.d.ts +30 -0
  62. package/types/transitionResolver.d.ts.map +11 -0
  63. package/types/types.d.ts +35 -42
  64. package/types/types.d.ts.map +2 -2
  65. package/dist/cjs/normalizeTransition.cjs +0 -164
  66. package/dist/cjs/normalizeTransition.native.js +0 -231
  67. package/dist/cjs/normalizeTransition.native.js.map +0 -1
  68. package/dist/esm/index.js.map +0 -1
  69. package/dist/esm/index.mjs.map +0 -1
  70. package/dist/esm/index.native.js.map +0 -1
  71. package/dist/esm/normalizeTransition.mjs +0 -134
  72. package/dist/esm/normalizeTransition.mjs.map +0 -1
  73. package/dist/esm/normalizeTransition.native.js +0 -198
  74. package/dist/esm/normalizeTransition.native.js.map +0 -1
  75. package/dist/esm/types.mjs.map +0 -1
  76. package/dist/esm/types.native.js.map +0 -1
  77. package/src/normalizeTransition.ts +0 -255
  78. package/types/normalizeTransition.d.ts +0 -54
  79. package/types/normalizeTransition.d.ts.map +0 -11
@@ -1,198 +0,0 @@
1
- function _type_of(obj) {
2
- "@swc/helpers - typeof";
3
-
4
- return obj && typeof Symbol !== "undefined" && 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) {
12
- return {
13
- default: null,
14
- enter: null,
15
- exit: null,
16
- delay: void 0,
17
- properties: {}
18
- };
19
- }
20
- if (typeof transition === "string") {
21
- return {
22
- default: transition,
23
- enter: null,
24
- exit: null,
25
- delay: void 0,
26
- properties: {}
27
- };
28
- }
29
- if (Array.isArray(transition)) {
30
- var [defaultAnimation, configObj] = transition;
31
- var properties = {};
32
- var springConfig = {};
33
- var delay;
34
- var enter = null;
35
- var exit = null;
36
- if (configObj && (typeof configObj === "undefined" ? "undefined" : _type_of(configObj)) === "object") {
37
- var _iteratorNormalCompletion = true,
38
- _didIteratorError = false,
39
- _iteratorError = void 0;
40
- try {
41
- for (var _iterator = Object.entries(configObj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
42
- var [key, value] = _step.value;
43
- if (key === "delay" && typeof value === "number") {
44
- delay = value;
45
- } else if (key === "enter" && typeof value === "string") {
46
- enter = value;
47
- } else if (key === "exit" && typeof value === "string") {
48
- exit = value;
49
- } else if (isSpringConfigKey(key) && value !== void 0) {
50
- springConfig[key] = value;
51
- } else if (value !== void 0) {
52
- properties[key] = value;
53
- }
54
- }
55
- } catch (err) {
56
- _didIteratorError = true;
57
- _iteratorError = err;
58
- } finally {
59
- try {
60
- if (!_iteratorNormalCompletion && _iterator.return != null) {
61
- _iterator.return();
62
- }
63
- } finally {
64
- if (_didIteratorError) {
65
- throw _iteratorError;
66
- }
67
- }
68
- }
69
- }
70
- return {
71
- default: defaultAnimation,
72
- enter,
73
- exit,
74
- delay,
75
- properties,
76
- config: Object.keys(springConfig).length > 0 ? springConfig : void 0
77
- };
78
- }
79
- if ((typeof transition === "undefined" ? "undefined" : _type_of(transition)) === "object") {
80
- var properties1 = {};
81
- var springConfig1 = {};
82
- var defaultAnimation1 = null;
83
- var enter1 = null;
84
- var exit1 = null;
85
- var delay1;
86
- var _iteratorNormalCompletion1 = true,
87
- _didIteratorError1 = false,
88
- _iteratorError1 = void 0;
89
- try {
90
- for (var _iterator1 = Object.entries(transition)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
91
- var [key1, value1] = _step1.value;
92
- if (key1 === "default" && typeof value1 === "string") {
93
- defaultAnimation1 = value1;
94
- } else if (key1 === "enter" && typeof value1 === "string") {
95
- enter1 = value1;
96
- } else if (key1 === "exit" && typeof value1 === "string") {
97
- exit1 = value1;
98
- } else if (key1 === "delay" && typeof value1 === "number") {
99
- delay1 = value1;
100
- } else if (isSpringConfigKey(key1) && value1 !== void 0) {
101
- springConfig1[key1] = value1;
102
- } else if (value1 !== void 0) {
103
- properties1[key1] = value1;
104
- }
105
- }
106
- } catch (err) {
107
- _didIteratorError1 = true;
108
- _iteratorError1 = err;
109
- } finally {
110
- try {
111
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
112
- _iterator1.return();
113
- }
114
- } finally {
115
- if (_didIteratorError1) {
116
- throw _iteratorError1;
117
- }
118
- }
119
- }
120
- return {
121
- default: defaultAnimation1,
122
- enter: enter1,
123
- exit: exit1,
124
- delay: delay1,
125
- properties: properties1,
126
- config: Object.keys(springConfig1).length > 0 ? springConfig1 : void 0
127
- };
128
- }
129
- return {
130
- default: null,
131
- enter: null,
132
- exit: null,
133
- delay: void 0,
134
- properties: {}
135
- };
136
- }
137
- function getAnimationForProperty(normalized, property) {
138
- var propertyAnimation = normalized.properties[property];
139
- if (propertyAnimation !== void 0) {
140
- return propertyAnimation;
141
- }
142
- return normalized.default;
143
- }
144
- function hasAnimation(normalized) {
145
- return normalized.default !== null || normalized.enter !== null || normalized.exit !== null || Object.keys(normalized.properties).length > 0;
146
- }
147
- function getAnimatedProperties(normalized) {
148
- return Object.keys(normalized.properties);
149
- }
150
- function getEffectiveAnimation(normalized, state) {
151
- if (state === "enter" && normalized.enter) {
152
- return normalized.enter;
153
- }
154
- if (state === "exit" && normalized.exit) {
155
- return normalized.exit;
156
- }
157
- return normalized.default;
158
- }
159
- function getAnimationConfigsForKeys(normalized, animations, keys, defaultAnimation) {
160
- var result = /* @__PURE__ */new Map();
161
- var _iteratorNormalCompletion = true,
162
- _didIteratorError = false,
163
- _iteratorError = void 0;
164
- try {
165
- for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
166
- var key = _step.value;
167
- var propAnimation = normalized.properties[key];
168
- var animationValue = null;
169
- if (typeof propAnimation === "string") {
170
- var _animations_propAnimation;
171
- animationValue = (_animations_propAnimation = animations[propAnimation]) !== null && _animations_propAnimation !== void 0 ? _animations_propAnimation : null;
172
- } else if (propAnimation && (typeof propAnimation === "undefined" ? "undefined" : _type_of(propAnimation)) === "object" && propAnimation.type) {
173
- var _animations_propAnimation_type;
174
- animationValue = (_animations_propAnimation_type = animations[propAnimation.type]) !== null && _animations_propAnimation_type !== void 0 ? _animations_propAnimation_type : null;
175
- }
176
- if (animationValue === null) {
177
- animationValue = defaultAnimation;
178
- }
179
- result.set(key, animationValue);
180
- }
181
- } catch (err) {
182
- _didIteratorError = true;
183
- _iteratorError = err;
184
- } finally {
185
- try {
186
- if (!_iteratorNormalCompletion && _iterator.return != null) {
187
- _iterator.return();
188
- }
189
- } finally {
190
- if (_didIteratorError) {
191
- throw _iteratorError;
192
- }
193
- }
194
- }
195
- return result;
196
- }
197
- export { getAnimatedProperties, getAnimationConfigsForKeys, getAnimationForProperty, getEffectiveAnimation, hasAnimation, normalizeTransition };
198
- //# sourceMappingURL=normalizeTransition.native.js.map
@@ -1 +0,0 @@
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","getAnimationForProperty","normalized","property"],"sources":["../../src/normalizeTransition.ts"],"sourcesContent":[null],"mappings":"AAOA,SAAMA,SAAAC,GAAA;EACJ;;EACA,OAAAA,GAAA,WAAAC,MAAA,oBAAAD,GAAA,CAAAE,WAAA,KAAAD,MAAA,qBAAAD,GAAA;AAAA;AACA,IACAG,kBAAA,sBAAAC,GAAA,EACA,aACA,WACA,QACA,WACA,YACA,YACD,qBAKD,UAAS,EACP,YAAO,EACT,QAcO;AAIL,SAAKC,iBAAYA,CAAAC,GAAA;EACf,OAAAH,kBAAO,CAAAI,GAAA,CAAAD,GAAA;AAAA;AACI,SACTE,mBAAOA,CAAAC,UAAA;EAAA,IACP,CAAAA,UAAM;IAAA,OACN;MACAC,OAAA,MAAa;MACfC,KAAA;MACFC,IAAA;MAGIC,KAAA,EAAO;MACTC,UAAO;IAAA;EACI;EACF,IACP,OAAML,UAAA;IAAA,OACN;MACAC,OAAA,EAAAD,UAAa;MACfE,KAAA;MACFC,IAAA;MAIIC,KAAA,EAAM;MACRC,UAAO;IACP;EACA;EACA,IAAAC,KAAI,CAAAC,OAAA,CAAAP,UAAA;IACJ,IAAI,CAAAQ,gBAAuB,EAAAC,SAAA,IAAAT,UAAA;IAC3B,IAAIK,UAAsB;IAE1B,IAAIK,YAAA,GAAa;IACf,IAAAN,K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,EAAA4B,MAAA;MACN3B,UAAI,EAAAsB,WAA2B;MAE/BH,MAAI,EAAAT,MAAO,CAAAU,IAAA,CAAAG,aAAkB,EAAAF,MAAU,OAAAE,aAAA;IACrC;EAA8C;EAM9C;IACF3B,OAAA;IAGAC,KAAI;IACFC,IAAA;IACFC,KAAA;IAEAC,UAAO,EAAI;EACb;AAEA;AACF,SAAAmC,wBAAAC,UAAA,EAAAC,QAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
@@ -1,255 +0,0 @@
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
- }
@@ -1,54 +0,0 @@
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
@@ -1,11 +0,0 @@
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
- }