@tamagui/animation-helpers 3.0.0-beta.924.1 → 3.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.
Files changed (69) hide show
  1. package/dist/cjs/index.cjs +20 -7
  2. package/dist/cjs/index.native.cjs +20 -7
  3. package/dist/cjs/index.native.js +20 -7
  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/esm/index.js +5 -2
  22. package/dist/esm/index.mjs +5 -2
  23. package/dist/esm/index.native.js +5 -2
  24. package/dist/esm/presets.mjs +57 -0
  25. package/dist/esm/presets.mjs.map +1 -0
  26. package/dist/esm/presets.native.js +57 -0
  27. package/dist/esm/presets.native.js.map +1 -0
  28. package/dist/esm/propertyNames.mjs +67 -0
  29. package/dist/esm/propertyNames.mjs.map +1 -0
  30. package/dist/esm/propertyNames.native.js +69 -0
  31. package/dist/esm/propertyNames.native.js.map +1 -0
  32. package/dist/esm/resolveTransition.mjs +315 -0
  33. package/dist/esm/resolveTransition.mjs.map +1 -0
  34. package/dist/esm/resolveTransition.native.js +392 -0
  35. package/dist/esm/resolveTransition.native.js.map +1 -0
  36. package/dist/esm/transitionResolver.mjs +11 -0
  37. package/dist/esm/transitionResolver.mjs.map +1 -0
  38. package/dist/esm/transitionResolver.native.js +12 -0
  39. package/dist/esm/transitionResolver.native.js.map +1 -0
  40. package/package.json +25 -3
  41. package/src/index.ts +39 -9
  42. package/src/presets.ts +40 -0
  43. package/src/propertyNames.ts +78 -0
  44. package/src/resolveTransition.ts +503 -0
  45. package/src/transitionResolver.ts +35 -0
  46. package/src/types.ts +42 -46
  47. package/types/index.d.ts +6 -2
  48. package/types/index.d.ts.map +2 -2
  49. package/types/presets.d.ts +79 -0
  50. package/types/presets.d.ts.map +11 -0
  51. package/types/propertyNames.d.ts +13 -0
  52. package/types/propertyNames.d.ts.map +11 -0
  53. package/types/resolveTransition.d.ts +108 -0
  54. package/types/resolveTransition.d.ts.map +11 -0
  55. package/types/transitionResolver.d.ts +30 -0
  56. package/types/transitionResolver.d.ts.map +11 -0
  57. package/types/types.d.ts +35 -42
  58. package/types/types.d.ts.map +2 -2
  59. package/dist/cjs/normalizeTransition.cjs +0 -173
  60. package/dist/cjs/normalizeTransition.native.cjs +0 -232
  61. package/dist/cjs/normalizeTransition.native.js +0 -234
  62. package/dist/cjs/normalizeTransition.native.js.map +0 -1
  63. package/dist/esm/normalizeTransition.mjs +0 -146
  64. package/dist/esm/normalizeTransition.mjs.map +0 -1
  65. package/dist/esm/normalizeTransition.native.js +0 -203
  66. package/dist/esm/normalizeTransition.native.js.map +0 -1
  67. package/src/normalizeTransition.ts +0 -255
  68. package/types/normalizeTransition.d.ts +0 -54
  69. package/types/normalizeTransition.d.ts.map +0 -11
@@ -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
- }