@tamagui/style-grammar 3.0.0-beta.924.1 → 3.0.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 (246) hide show
  1. package/dist/cjs/ast/payloadShape.cjs +45 -17
  2. package/dist/cjs/ast/payloadShape.native.cjs +45 -17
  3. package/dist/cjs/ast/payloadShape.native.js +45 -17
  4. package/dist/cjs/ast/payloadShape.native.js.map +1 -1
  5. package/dist/cjs/ast/resolvePayload.cjs +16 -9
  6. package/dist/cjs/ast/resolvePayload.native.cjs +16 -9
  7. package/dist/cjs/ast/resolvePayload.native.js +16 -9
  8. package/dist/cjs/ast/resolvePayload.native.js.map +1 -1
  9. package/dist/cjs/programs/lowerProgram.cjs +2 -2
  10. package/dist/cjs/programs/lowerProgram.native.cjs +2 -2
  11. package/dist/cjs/programs/lowerProgram.native.js +2 -2
  12. package/dist/cjs/programs/lowerProgram.native.js.map +1 -1
  13. package/dist/cjs/runtime/clauseIdentity.cjs +9 -28
  14. package/dist/cjs/runtime/clauseIdentity.native.cjs +9 -28
  15. package/dist/cjs/runtime/clauseIdentity.native.js +9 -28
  16. package/dist/cjs/runtime/clauseIdentity.native.js.map +1 -1
  17. package/dist/cjs/runtime/clausePrecedence.cjs +2 -2
  18. package/dist/cjs/runtime/clausePrecedence.native.cjs +3 -10
  19. package/dist/cjs/runtime/clausePrecedence.native.js +3 -10
  20. package/dist/cjs/runtime/clausePrecedence.native.js.map +1 -1
  21. package/dist/cjs/runtime/modifierVocabulary.native.cjs +1 -8
  22. package/dist/cjs/runtime/modifierVocabulary.native.js +1 -8
  23. package/dist/cjs/runtime/modifierVocabulary.native.js.map +1 -1
  24. package/dist/cjs/runtime/scanFlatValue.cjs +58 -7
  25. package/dist/cjs/runtime/scanFlatValue.native.cjs +58 -7
  26. package/dist/cjs/runtime/scanFlatValue.native.js +58 -7
  27. package/dist/cjs/runtime/scanFlatValue.native.js.map +1 -1
  28. package/dist/cjs/runtime/spring.cjs +123 -0
  29. package/dist/cjs/runtime/spring.native.cjs +131 -0
  30. package/dist/cjs/runtime/spring.native.js +133 -0
  31. package/dist/cjs/runtime/spring.native.js.map +1 -0
  32. package/dist/cjs/runtime/stateModifiers.cjs +23 -1
  33. package/dist/cjs/runtime/stateModifiers.native.cjs +23 -1
  34. package/dist/cjs/runtime/stateModifiers.native.js +23 -1
  35. package/dist/cjs/runtime/stateModifiers.native.js.map +1 -1
  36. package/dist/cjs/runtime/tokenCategories.cjs +3 -0
  37. package/dist/cjs/runtime/tokenCategories.native.cjs +3 -0
  38. package/dist/cjs/runtime/tokenCategories.native.js +3 -0
  39. package/dist/cjs/runtime/tokenCategories.native.js.map +1 -1
  40. package/dist/cjs/runtime/unitlessNumbers.cjs +0 -5
  41. package/dist/cjs/runtime/unitlessNumbers.native.cjs +0 -5
  42. package/dist/cjs/runtime/unitlessNumbers.native.js +0 -5
  43. package/dist/cjs/runtime/unitlessNumbers.native.js.map +1 -1
  44. package/dist/cjs/runtime.cjs +11 -0
  45. package/dist/cjs/runtime.native.cjs +11 -0
  46. package/dist/cjs/runtime.native.js +11 -0
  47. package/dist/cjs/runtime.native.js.map +1 -1
  48. package/dist/cjs/shorthands/transition.cjs +111 -36
  49. package/dist/cjs/shorthands/transition.native.cjs +113 -36
  50. package/dist/cjs/shorthands/transition.native.js +113 -36
  51. package/dist/cjs/shorthands/transition.native.js.map +1 -1
  52. package/dist/cjs/shorthands/transitionAlign.cjs +13 -10
  53. package/dist/cjs/shorthands/transitionAlign.native.cjs +14 -11
  54. package/dist/cjs/shorthands/transitionAlign.native.js +14 -11
  55. package/dist/cjs/shorthands/transitionAlign.native.js.map +1 -1
  56. package/dist/cjs/shorthands/transitionLegacy.cjs +263 -126
  57. package/dist/cjs/shorthands/transitionLegacy.native.cjs +333 -155
  58. package/dist/cjs/shorthands/transitionLegacy.native.js +333 -155
  59. package/dist/cjs/shorthands/transitionLegacy.native.js.map +1 -1
  60. package/dist/cjs/shorthands/transitionNative.cjs +5 -5
  61. package/dist/cjs/shorthands/transitionNative.native.cjs +8 -7
  62. package/dist/cjs/shorthands/transitionNative.native.js +8 -7
  63. package/dist/cjs/shorthands/transitionNative.native.js.map +1 -1
  64. package/dist/cjs/shorthands/transitionObject.cjs +302 -0
  65. package/dist/cjs/shorthands/transitionObject.native.cjs +347 -0
  66. package/dist/cjs/shorthands/transitionObject.native.js +349 -0
  67. package/dist/cjs/shorthands/transitionObject.native.js.map +1 -0
  68. package/dist/cjs/tooling/candidate.cjs +254 -15
  69. package/dist/cjs/tooling/candidate.native.cjs +314 -62
  70. package/dist/cjs/tooling/candidate.native.js +314 -62
  71. package/dist/cjs/tooling/candidate.native.js.map +1 -1
  72. package/dist/cjs/tooling/config.cjs +19 -9
  73. package/dist/cjs/tooling/config.native.cjs +25 -26
  74. package/dist/cjs/tooling/config.native.js +25 -26
  75. package/dist/cjs/tooling/config.native.js.map +1 -1
  76. package/dist/cjs/tooling/registry.cjs +579 -11
  77. package/dist/cjs/tooling/registry.native.cjs +579 -11
  78. package/dist/cjs/tooling/registry.native.js +579 -11
  79. package/dist/cjs/tooling/registry.native.js.map +1 -1
  80. package/dist/cjs/tooling/toolingDiagnostics.cjs +306 -10
  81. package/dist/cjs/tooling/toolingDiagnostics.native.cjs +408 -48
  82. package/dist/cjs/tooling/toolingDiagnostics.native.js +408 -48
  83. package/dist/cjs/tooling/toolingDiagnostics.native.js.map +1 -1
  84. package/dist/cjs/tooling/toolingRegistry.cjs +6 -1
  85. package/dist/cjs/tooling/toolingRegistry.native.cjs +9 -1
  86. package/dist/cjs/tooling/toolingRegistry.native.js +9 -1
  87. package/dist/cjs/tooling/toolingRegistry.native.js.map +1 -1
  88. package/dist/cjs/tooling.cjs +1 -0
  89. package/dist/cjs/tooling.native.cjs +1 -0
  90. package/dist/cjs/tooling.native.js +1 -0
  91. package/dist/cjs/tooling.native.js.map +1 -1
  92. package/dist/cjs/transitions.cjs +38 -0
  93. package/dist/cjs/transitions.native.cjs +40 -0
  94. package/dist/cjs/transitions.native.js +42 -0
  95. package/dist/cjs/transitions.native.js.map +1 -0
  96. package/dist/esm/ast/payloadShape.mjs +45 -17
  97. package/dist/esm/ast/payloadShape.mjs.map +1 -1
  98. package/dist/esm/ast/payloadShape.native.js +45 -17
  99. package/dist/esm/ast/payloadShape.native.js.map +1 -1
  100. package/dist/esm/ast/resolvePayload.mjs +16 -9
  101. package/dist/esm/ast/resolvePayload.mjs.map +1 -1
  102. package/dist/esm/ast/resolvePayload.native.js +16 -9
  103. package/dist/esm/ast/resolvePayload.native.js.map +1 -1
  104. package/dist/esm/programs/lowerProgram.mjs +2 -2
  105. package/dist/esm/programs/lowerProgram.mjs.map +1 -1
  106. package/dist/esm/programs/lowerProgram.native.js +2 -2
  107. package/dist/esm/programs/lowerProgram.native.js.map +1 -1
  108. package/dist/esm/runtime/clauseIdentity.mjs +2 -22
  109. package/dist/esm/runtime/clauseIdentity.mjs.map +1 -1
  110. package/dist/esm/runtime/clauseIdentity.native.js +2 -22
  111. package/dist/esm/runtime/clauseIdentity.native.js.map +1 -1
  112. package/dist/esm/runtime/clausePrecedence.mjs +2 -2
  113. package/dist/esm/runtime/clausePrecedence.mjs.map +1 -1
  114. package/dist/esm/runtime/clausePrecedence.native.js +3 -10
  115. package/dist/esm/runtime/clausePrecedence.native.js.map +1 -1
  116. package/dist/esm/runtime/modifierVocabulary.native.js +1 -8
  117. package/dist/esm/runtime/modifierVocabulary.native.js.map +1 -1
  118. package/dist/esm/runtime/scanFlatValue.mjs +59 -7
  119. package/dist/esm/runtime/scanFlatValue.mjs.map +1 -1
  120. package/dist/esm/runtime/scanFlatValue.native.js +59 -7
  121. package/dist/esm/runtime/scanFlatValue.native.js.map +1 -1
  122. package/dist/esm/runtime/spring.mjs +93 -0
  123. package/dist/esm/runtime/spring.mjs.map +1 -0
  124. package/dist/esm/runtime/spring.native.js +99 -0
  125. package/dist/esm/runtime/spring.native.js.map +1 -0
  126. package/dist/esm/runtime/stateModifiers.mjs +22 -2
  127. package/dist/esm/runtime/stateModifiers.mjs.map +1 -1
  128. package/dist/esm/runtime/stateModifiers.native.js +22 -2
  129. package/dist/esm/runtime/stateModifiers.native.js.map +1 -1
  130. package/dist/esm/runtime/tokenCategories.mjs +3 -0
  131. package/dist/esm/runtime/tokenCategories.mjs.map +1 -1
  132. package/dist/esm/runtime/tokenCategories.native.js +3 -0
  133. package/dist/esm/runtime/tokenCategories.native.js.map +1 -1
  134. package/dist/esm/runtime/unitlessNumbers.mjs +0 -5
  135. package/dist/esm/runtime/unitlessNumbers.mjs.map +1 -1
  136. package/dist/esm/runtime/unitlessNumbers.native.js +0 -5
  137. package/dist/esm/runtime/unitlessNumbers.native.js.map +1 -1
  138. package/dist/esm/runtime.mjs +4 -2
  139. package/dist/esm/runtime.native.js +4 -2
  140. package/dist/esm/shorthands/transition.mjs +111 -36
  141. package/dist/esm/shorthands/transition.mjs.map +1 -1
  142. package/dist/esm/shorthands/transition.native.js +113 -36
  143. package/dist/esm/shorthands/transition.native.js.map +1 -1
  144. package/dist/esm/shorthands/transitionAlign.mjs +13 -10
  145. package/dist/esm/shorthands/transitionAlign.mjs.map +1 -1
  146. package/dist/esm/shorthands/transitionAlign.native.js +14 -11
  147. package/dist/esm/shorthands/transitionAlign.native.js.map +1 -1
  148. package/dist/esm/shorthands/transitionLegacy.mjs +260 -126
  149. package/dist/esm/shorthands/transitionLegacy.mjs.map +1 -1
  150. package/dist/esm/shorthands/transitionLegacy.native.js +330 -155
  151. package/dist/esm/shorthands/transitionLegacy.native.js.map +1 -1
  152. package/dist/esm/shorthands/transitionNative.mjs +5 -5
  153. package/dist/esm/shorthands/transitionNative.mjs.map +1 -1
  154. package/dist/esm/shorthands/transitionNative.native.js +8 -7
  155. package/dist/esm/shorthands/transitionNative.native.js.map +1 -1
  156. package/dist/esm/shorthands/transitionObject.mjs +280 -0
  157. package/dist/esm/shorthands/transitionObject.mjs.map +1 -0
  158. package/dist/esm/shorthands/transitionObject.native.js +323 -0
  159. package/dist/esm/shorthands/transitionObject.native.js.map +1 -0
  160. package/dist/esm/tooling/candidate.mjs +250 -16
  161. package/dist/esm/tooling/candidate.mjs.map +1 -1
  162. package/dist/esm/tooling/candidate.native.js +310 -63
  163. package/dist/esm/tooling/candidate.native.js.map +1 -1
  164. package/dist/esm/tooling/config.mjs +18 -9
  165. package/dist/esm/tooling/config.mjs.map +1 -1
  166. package/dist/esm/tooling/config.native.js +24 -26
  167. package/dist/esm/tooling/config.native.js.map +1 -1
  168. package/dist/esm/tooling/registry.mjs +579 -11
  169. package/dist/esm/tooling/registry.mjs.map +1 -1
  170. package/dist/esm/tooling/registry.native.js +579 -11
  171. package/dist/esm/tooling/registry.native.js.map +1 -1
  172. package/dist/esm/tooling/toolingDiagnostics.mjs +306 -11
  173. package/dist/esm/tooling/toolingDiagnostics.mjs.map +1 -1
  174. package/dist/esm/tooling/toolingDiagnostics.native.js +408 -49
  175. package/dist/esm/tooling/toolingDiagnostics.native.js.map +1 -1
  176. package/dist/esm/tooling/toolingRegistry.mjs +6 -1
  177. package/dist/esm/tooling/toolingRegistry.mjs.map +1 -1
  178. package/dist/esm/tooling/toolingRegistry.native.js +9 -1
  179. package/dist/esm/tooling/toolingRegistry.native.js.map +1 -1
  180. package/dist/esm/tooling.mjs +2 -0
  181. package/dist/esm/tooling.native.js +2 -0
  182. package/dist/esm/transitions.mjs +5 -0
  183. package/dist/esm/transitions.native.js +5 -0
  184. package/package.json +21 -3
  185. package/src/ast/payloadShape.ts +44 -16
  186. package/src/ast/resolvePayload.ts +28 -13
  187. package/src/programs/lowerProgram.ts +9 -4
  188. package/src/runtime/clauseIdentity.ts +8 -31
  189. package/src/runtime/clausePrecedence.ts +2 -10
  190. package/src/runtime/scanFlatValue.ts +81 -9
  191. package/src/runtime/spring.ts +208 -0
  192. package/src/runtime/stateModifiers.ts +31 -1
  193. package/src/runtime/tokenCategories.ts +3 -0
  194. package/src/runtime/unitlessNumbers.ts +0 -5
  195. package/src/runtime.ts +13 -0
  196. package/src/shorthands/transition.ts +159 -44
  197. package/src/shorthands/transitionAlign.ts +22 -12
  198. package/src/shorthands/transitionLegacy.ts +376 -156
  199. package/src/shorthands/transitionNative.ts +8 -11
  200. package/src/shorthands/transitionObject.ts +369 -0
  201. package/src/tooling/candidate.ts +269 -14
  202. package/src/tooling/config.ts +25 -9
  203. package/src/tooling/registry.ts +339 -12
  204. package/src/tooling/toolingDiagnostics.ts +474 -9
  205. package/src/tooling/toolingRegistry.ts +6 -1
  206. package/src/tooling.ts +1 -0
  207. package/src/transitions.ts +42 -0
  208. package/types/ast/payloadShape.d.ts.map +2 -2
  209. package/types/ast/resolvePayload.d.ts +5 -4
  210. package/types/ast/resolvePayload.d.ts.map +2 -2
  211. package/types/programs/lowerProgram.d.ts +4 -2
  212. package/types/programs/lowerProgram.d.ts.map +2 -2
  213. package/types/runtime/clauseIdentity.d.ts +1 -4
  214. package/types/runtime/clauseIdentity.d.ts.map +2 -2
  215. package/types/runtime/clausePrecedence.d.ts.map +2 -2
  216. package/types/runtime/scanFlatValue.d.ts +1 -1
  217. package/types/runtime/scanFlatValue.d.ts.map +2 -2
  218. package/types/runtime/spring.d.ts +61 -0
  219. package/types/runtime/spring.d.ts.map +11 -0
  220. package/types/runtime/stateModifiers.d.ts +4 -0
  221. package/types/runtime/stateModifiers.d.ts.map +2 -2
  222. package/types/runtime/tokenCategories.d.ts.map +2 -2
  223. package/types/runtime/unitlessNumbers.d.ts.map +2 -2
  224. package/types/runtime.d.ts +3 -1
  225. package/types/runtime.d.ts.map +2 -2
  226. package/types/shorthands/transition.d.ts +26 -5
  227. package/types/shorthands/transition.d.ts.map +2 -2
  228. package/types/shorthands/transitionAlign.d.ts.map +2 -2
  229. package/types/shorthands/transitionLegacy.d.ts +19 -4
  230. package/types/shorthands/transitionLegacy.d.ts.map +2 -2
  231. package/types/shorthands/transitionNative.d.ts.map +1 -1
  232. package/types/shorthands/transitionObject.d.ts +49 -0
  233. package/types/shorthands/transitionObject.d.ts.map +11 -0
  234. package/types/tooling/candidate.d.ts +13 -0
  235. package/types/tooling/candidate.d.ts.map +2 -2
  236. package/types/tooling/config.d.ts +8 -1
  237. package/types/tooling/config.d.ts.map +2 -2
  238. package/types/tooling/registry.d.ts +4 -2
  239. package/types/tooling/registry.d.ts.map +2 -2
  240. package/types/tooling/toolingDiagnostics.d.ts +3 -1
  241. package/types/tooling/toolingDiagnostics.d.ts.map +2 -2
  242. package/types/tooling/toolingRegistry.d.ts.map +2 -2
  243. package/types/tooling.d.ts +1 -0
  244. package/types/tooling.d.ts.map +2 -2
  245. package/types/transitions.d.ts +5 -0
  246. package/types/transitions.d.ts.map +11 -0
@@ -0,0 +1,369 @@
1
+ // the object spelling of `transition`, lowered into the same IR as the string
2
+ // shorthand and the five longhands. there is no second parser and no second set
3
+ // of semantics: this file only decides which IR entries an object describes.
4
+ //
5
+ // base config keys build the entry for the `properties` list (default `all`).
6
+ // per-property keys build LATER entries, which win for that property under the
7
+ // css last-wins rule, exactly as `transition: all 200ms, opacity 150ms` does.
8
+ // entries do NOT inherit fields from the base, because the string spelling
9
+ // does not either. reach for `preset` when you want a shared starting point.
10
+
11
+ import {
12
+ parseTransition,
13
+ type TransitionBehavior,
14
+ type TransitionDiagnostic,
15
+ type TransitionEntry,
16
+ type TransitionParseResult,
17
+ type TransitionTiming,
18
+ } from './transition'
19
+ import { springToDurationBounce } from '../runtime/spring'
20
+
21
+ /** low-level spring physics: a projection of duration+bounce, not a second API */
22
+ export interface SpringEscapeHatch {
23
+ stiffness?: number
24
+ damping?: number
25
+ mass?: number
26
+ velocity?: number
27
+ overshootClamping?: boolean
28
+ restDisplacementThreshold?: number
29
+ restSpeedThreshold?: number
30
+ }
31
+
32
+ export interface TransitionObjectBase {
33
+ preset?: string
34
+ duration?: number | string
35
+ bounce?: number
36
+ easing?: string
37
+ delay?: number | string
38
+ behavior?: TransitionBehavior
39
+ /** the css transition-property list this base entry applies to */
40
+ properties?: string
41
+ spring?: SpringEscapeHatch
42
+ /**
43
+ * the transition to use while mounting. prefer colocating it with the styles
44
+ * it animates: `enterStyle={{ opacity: 0, transition: '200ms' }}`.
45
+ */
46
+ enter?: TransitionObjectValue
47
+ /** the transition to use while unmounting. see `enter`. */
48
+ exit?: TransitionObjectValue
49
+ }
50
+
51
+ export type TransitionObjectValue =
52
+ | string
53
+ | (TransitionObjectBase & { [property: string]: unknown })
54
+
55
+ /**
56
+ * every key that configures the transition itself. anything else in the object
57
+ * is a property name. closed on purpose: an unrecognized key is a diagnostic,
58
+ * never a silent per-property transition on a property that does not exist.
59
+ */
60
+ export const TRANSITION_RESERVED_KEYS: ReadonlySet<string> = new Set([
61
+ 'preset',
62
+ 'duration',
63
+ 'bounce',
64
+ 'easing',
65
+ 'delay',
66
+ 'behavior',
67
+ 'properties',
68
+ 'spring',
69
+ 'enter',
70
+ 'exit',
71
+ ])
72
+
73
+ const behaviorValues = new Set(['normal', 'allow-discrete'])
74
+ const springKeys = new Set([
75
+ 'stiffness',
76
+ 'damping',
77
+ 'mass',
78
+ 'velocity',
79
+ 'overshootClamping',
80
+ 'restDisplacementThreshold',
81
+ 'restSpeedThreshold',
82
+ ])
83
+
84
+ function time(value: number | string, label: string): string | TransitionDiagnostic {
85
+ if (typeof value === 'number') {
86
+ if (!Number.isFinite(value)) {
87
+ return {
88
+ code: 'transition-invalid-token',
89
+ token: String(value),
90
+ message: `${label} must be a finite number of milliseconds`,
91
+ }
92
+ }
93
+ return `${value}ms`
94
+ }
95
+ if (typeof value === 'string' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(ms|s)$/.test(value)) {
96
+ return value
97
+ }
98
+ return {
99
+ code: 'transition-invalid-token',
100
+ token: String(value),
101
+ message: `${label} must be a number of milliseconds or a css time`,
102
+ }
103
+ }
104
+
105
+ /**
106
+ * builds the timing atom a base object describes, or undefined when it
107
+ * describes no timing at all (an object carrying only per-property keys).
108
+ */
109
+ function timingFor(
110
+ base: TransitionObjectBase
111
+ ): TransitionTiming | TransitionDiagnostic | undefined {
112
+ const hasSpringPhysics =
113
+ !!base.spring && Object.keys(base.spring).some((key) => springKeys.has(key))
114
+ const wantsSpring = base.bounce !== undefined || hasSpringPhysics
115
+
116
+ if (base.preset !== undefined) {
117
+ if (typeof base.preset !== 'string' || !base.preset) {
118
+ return {
119
+ code: 'transition-invalid-token',
120
+ token: String(base.preset),
121
+ message: 'preset must be the name of a configured animation',
122
+ }
123
+ }
124
+ // the preset stays opaque here: only the driver holds the config that
125
+ // gives it values, so overrides ride along and are applied at resolve time
126
+ const config: Record<string, unknown> = {}
127
+ if (base.duration !== undefined) config.duration = base.duration
128
+ if (base.bounce !== undefined) config.bounce = base.bounce
129
+ if (base.easing !== undefined) config.easing = base.easing
130
+ if (base.spring) Object.assign(config, base.spring)
131
+ return Object.keys(config).length
132
+ ? { type: 'preset', name: base.preset, config }
133
+ : { type: 'preset', name: base.preset }
134
+ }
135
+
136
+ if (wantsSpring) {
137
+ if (base.easing !== undefined) {
138
+ return {
139
+ code: 'transition-invalid-spring',
140
+ message:
141
+ 'a spring carries its own easing; drop `easing`, or drop `bounce`/`spring` for a timing',
142
+ }
143
+ }
144
+
145
+ let duration: string
146
+ let bounce: number
147
+
148
+ if (base.duration !== undefined) {
149
+ const parsed = time(base.duration, 'duration')
150
+ if (typeof parsed !== 'string') return parsed
151
+ duration = parsed
152
+ bounce = base.bounce ?? 0
153
+ } else if (hasSpringPhysics) {
154
+ // derive the canonical pair so the IR always carries one representation,
155
+ // with the authored physics riding along for drivers that take them raw
156
+ const stiffness = base.spring!.stiffness
157
+ const mass = base.spring!.mass ?? 1
158
+ if (stiffness === undefined) {
159
+ return {
160
+ code: 'transition-invalid-spring',
161
+ message: 'a spring needs `duration`, or `spring.stiffness` to derive one from',
162
+ }
163
+ }
164
+ const damping = base.spring!.damping ?? 2 * Math.sqrt(stiffness * mass)
165
+ const canonical = springToDurationBounce({ stiffness, damping, mass })
166
+ duration = `${canonical.duration}ms`
167
+ bounce = base.bounce ?? canonical.bounce
168
+ } else {
169
+ return {
170
+ code: 'transition-invalid-spring',
171
+ message: '`bounce` needs a `duration` to go with it',
172
+ }
173
+ }
174
+
175
+ if (!Number.isFinite(bounce) || bounce <= -1 || bounce >= 1) {
176
+ return {
177
+ code: 'transition-invalid-spring',
178
+ token: String(bounce),
179
+ message: 'bounce must be a number between -1 and 1 (0 is critically damped)',
180
+ }
181
+ }
182
+
183
+ return base.spring
184
+ ? { type: 'spring', duration, bounce, config: { ...base.spring } }
185
+ : { type: 'spring', duration, bounce }
186
+ }
187
+
188
+ if (base.duration === undefined && base.easing === undefined) return undefined
189
+
190
+ const duration = base.duration === undefined ? '0s' : time(base.duration, 'duration')
191
+ if (typeof duration !== 'string') return duration
192
+ return {
193
+ type: 'css',
194
+ duration,
195
+ timingFunction: base.easing === undefined ? 'ease' : base.easing,
196
+ }
197
+ }
198
+
199
+ /**
200
+ * lowers the transition object form into TransitionIR.
201
+ *
202
+ * @param presetNames configured animation names, so per-property strings
203
+ * resolve presets the same way the shorthand does
204
+ * @param knownProperties when given, any non-reserved key outside it is a
205
+ * diagnostic instead of a silently-ignored per-property entry
206
+ */
207
+ export function parseTransitionObject(
208
+ input: TransitionObjectValue,
209
+ presetNames: ReadonlySet<string> = new Set(),
210
+ knownProperties?: ReadonlySet<string>
211
+ ): TransitionParseResult {
212
+ if (typeof input === 'string') return parseTransition(input, presetNames)
213
+
214
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
215
+ return {
216
+ ok: false,
217
+ diagnostics: [
218
+ {
219
+ code: 'transition-invalid-token',
220
+ message: 'transition must be a css transition string or a config object',
221
+ },
222
+ ],
223
+ }
224
+ }
225
+
226
+ const diagnostics: TransitionDiagnostic[] = []
227
+ const base = input as TransitionObjectBase
228
+ const entries: TransitionEntry[] = []
229
+
230
+ let delay = '0s'
231
+ if (base.delay !== undefined) {
232
+ const parsed = time(base.delay, 'delay')
233
+ if (typeof parsed === 'string') delay = parsed
234
+ else diagnostics.push(parsed)
235
+ }
236
+
237
+ let behavior: TransitionBehavior = 'normal'
238
+ if (base.behavior !== undefined) {
239
+ if (behaviorValues.has(base.behavior)) behavior = base.behavior
240
+ else {
241
+ diagnostics.push({
242
+ code: 'transition-invalid-token',
243
+ token: String(base.behavior),
244
+ message: `"${base.behavior}" is not a transition behavior`,
245
+ })
246
+ }
247
+ }
248
+
249
+ const timing = timingFor(base)
250
+ if (timing !== undefined && 'code' in timing) diagnostics.push(timing)
251
+ else if (timing !== undefined) {
252
+ // an object with no timing keys describes no base entry at all, so only
253
+ // its listed properties transition. same reading as `transition: opacity
254
+ // 150ms` with no `all` clause.
255
+ const properties = (base.properties ?? 'all').split(',')
256
+ for (const property of properties) {
257
+ const trimmed = property.trim()
258
+ if (!trimmed) {
259
+ diagnostics.push({
260
+ code: 'transition-empty-item',
261
+ message: 'transition property lists cannot contain an empty item',
262
+ })
263
+ continue
264
+ }
265
+ entries.push({ property: trimmed, timing, delay, behavior })
266
+ }
267
+ } else if (base.properties !== undefined) {
268
+ diagnostics.push({
269
+ code: 'transition-invalid-list',
270
+ message: '`properties` needs a duration, preset, bounce, or spring to apply',
271
+ })
272
+ }
273
+
274
+ for (const key in input) {
275
+ if (TRANSITION_RESERVED_KEYS.has(key)) continue
276
+ const value = (input as Record<string, unknown>)[key]
277
+ if (value === undefined) continue
278
+
279
+ if (knownProperties && !knownProperties.has(key)) {
280
+ diagnostics.push({
281
+ code: 'transition-invalid-token',
282
+ token: key,
283
+ message: `"${key}" is not a style property or a transition setting`,
284
+ })
285
+ continue
286
+ }
287
+
288
+ if (typeof value === 'string') {
289
+ const parsed = parseTransition(value, presetNames)
290
+ if (!parsed.ok) {
291
+ diagnostics.push(...parsed.diagnostics)
292
+ continue
293
+ }
294
+ if (parsed.value.kind === 'global') {
295
+ diagnostics.push({
296
+ code: 'transition-invalid-list',
297
+ token: key,
298
+ message: `CSS-wide value "${value}" cannot apply to a single property`,
299
+ })
300
+ continue
301
+ }
302
+ // the property key names the property, so a bare `"150ms ease-out"`
303
+ // needs no property token of its own
304
+ for (const entry of parsed.value.entries) {
305
+ entries.push({
306
+ ...entry,
307
+ property: entry.property === 'all' ? key : entry.property,
308
+ })
309
+ }
310
+ continue
311
+ }
312
+
313
+ if (value && typeof value === 'object') {
314
+ const nested = parseTransitionObject(
315
+ { ...(value as TransitionObjectBase), properties: key },
316
+ presetNames,
317
+ knownProperties
318
+ )
319
+ if (!nested.ok) {
320
+ diagnostics.push(...nested.diagnostics)
321
+ continue
322
+ }
323
+ if (nested.value.kind === 'transition') entries.push(...nested.value.entries)
324
+ continue
325
+ }
326
+
327
+ diagnostics.push({
328
+ code: 'transition-invalid-token',
329
+ token: key,
330
+ message: `"${key}" must be a transition string or a transition config object`,
331
+ })
332
+ }
333
+
334
+ // mount and unmount transitions are their own entry lists rather than
335
+ // entries in this one, because they never apply at the same time as it
336
+ const states: {
337
+ enter?: readonly TransitionEntry[]
338
+ exit?: readonly TransitionEntry[]
339
+ } = {}
340
+ for (const state of ['enter', 'exit'] as const) {
341
+ const value = base[state]
342
+ if (value === undefined) continue
343
+ const parsed = parseTransitionObject(value, presetNames, knownProperties)
344
+ if (!parsed.ok) {
345
+ diagnostics.push(...parsed.diagnostics)
346
+ continue
347
+ }
348
+ if (parsed.value.kind === 'transition') states[state] = parsed.value.entries
349
+ }
350
+
351
+ if (diagnostics.length) return { ok: false, diagnostics }
352
+
353
+ if (!entries.length && !states.enter && !states.exit) {
354
+ return {
355
+ ok: false,
356
+ diagnostics: [
357
+ {
358
+ code: 'transition-empty-item',
359
+ message: 'transition object describes no transition',
360
+ },
361
+ ],
362
+ }
363
+ }
364
+
365
+ return {
366
+ ok: true,
367
+ value: { kind: 'transition', entries, enter: states.enter, exit: states.exit },
368
+ }
369
+ }