@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.
- package/dist/cjs/ast/payloadShape.cjs +45 -17
- package/dist/cjs/ast/payloadShape.native.cjs +45 -17
- package/dist/cjs/ast/payloadShape.native.js +45 -17
- package/dist/cjs/ast/payloadShape.native.js.map +1 -1
- package/dist/cjs/ast/resolvePayload.cjs +16 -9
- package/dist/cjs/ast/resolvePayload.native.cjs +16 -9
- package/dist/cjs/ast/resolvePayload.native.js +16 -9
- package/dist/cjs/ast/resolvePayload.native.js.map +1 -1
- package/dist/cjs/programs/lowerProgram.cjs +2 -2
- package/dist/cjs/programs/lowerProgram.native.cjs +2 -2
- package/dist/cjs/programs/lowerProgram.native.js +2 -2
- package/dist/cjs/programs/lowerProgram.native.js.map +1 -1
- package/dist/cjs/runtime/clauseIdentity.cjs +9 -28
- package/dist/cjs/runtime/clauseIdentity.native.cjs +9 -28
- package/dist/cjs/runtime/clauseIdentity.native.js +9 -28
- package/dist/cjs/runtime/clauseIdentity.native.js.map +1 -1
- package/dist/cjs/runtime/clausePrecedence.cjs +2 -2
- package/dist/cjs/runtime/clausePrecedence.native.cjs +3 -10
- package/dist/cjs/runtime/clausePrecedence.native.js +3 -10
- package/dist/cjs/runtime/clausePrecedence.native.js.map +1 -1
- package/dist/cjs/runtime/modifierVocabulary.native.cjs +1 -8
- package/dist/cjs/runtime/modifierVocabulary.native.js +1 -8
- package/dist/cjs/runtime/modifierVocabulary.native.js.map +1 -1
- package/dist/cjs/runtime/scanFlatValue.cjs +58 -7
- package/dist/cjs/runtime/scanFlatValue.native.cjs +58 -7
- package/dist/cjs/runtime/scanFlatValue.native.js +58 -7
- package/dist/cjs/runtime/scanFlatValue.native.js.map +1 -1
- package/dist/cjs/runtime/spring.cjs +123 -0
- package/dist/cjs/runtime/spring.native.cjs +131 -0
- package/dist/cjs/runtime/spring.native.js +133 -0
- package/dist/cjs/runtime/spring.native.js.map +1 -0
- package/dist/cjs/runtime/stateModifiers.cjs +23 -1
- package/dist/cjs/runtime/stateModifiers.native.cjs +23 -1
- package/dist/cjs/runtime/stateModifiers.native.js +23 -1
- package/dist/cjs/runtime/stateModifiers.native.js.map +1 -1
- package/dist/cjs/runtime/tokenCategories.cjs +3 -0
- package/dist/cjs/runtime/tokenCategories.native.cjs +3 -0
- package/dist/cjs/runtime/tokenCategories.native.js +3 -0
- package/dist/cjs/runtime/tokenCategories.native.js.map +1 -1
- package/dist/cjs/runtime/unitlessNumbers.cjs +0 -5
- package/dist/cjs/runtime/unitlessNumbers.native.cjs +0 -5
- package/dist/cjs/runtime/unitlessNumbers.native.js +0 -5
- package/dist/cjs/runtime/unitlessNumbers.native.js.map +1 -1
- package/dist/cjs/runtime.cjs +11 -0
- package/dist/cjs/runtime.native.cjs +11 -0
- package/dist/cjs/runtime.native.js +11 -0
- package/dist/cjs/runtime.native.js.map +1 -1
- package/dist/cjs/shorthands/transition.cjs +111 -36
- package/dist/cjs/shorthands/transition.native.cjs +113 -36
- package/dist/cjs/shorthands/transition.native.js +113 -36
- package/dist/cjs/shorthands/transition.native.js.map +1 -1
- package/dist/cjs/shorthands/transitionAlign.cjs +13 -10
- package/dist/cjs/shorthands/transitionAlign.native.cjs +14 -11
- package/dist/cjs/shorthands/transitionAlign.native.js +14 -11
- package/dist/cjs/shorthands/transitionAlign.native.js.map +1 -1
- package/dist/cjs/shorthands/transitionLegacy.cjs +263 -126
- package/dist/cjs/shorthands/transitionLegacy.native.cjs +333 -155
- package/dist/cjs/shorthands/transitionLegacy.native.js +333 -155
- package/dist/cjs/shorthands/transitionLegacy.native.js.map +1 -1
- package/dist/cjs/shorthands/transitionNative.cjs +5 -5
- package/dist/cjs/shorthands/transitionNative.native.cjs +8 -7
- package/dist/cjs/shorthands/transitionNative.native.js +8 -7
- package/dist/cjs/shorthands/transitionNative.native.js.map +1 -1
- package/dist/cjs/shorthands/transitionObject.cjs +302 -0
- package/dist/cjs/shorthands/transitionObject.native.cjs +347 -0
- package/dist/cjs/shorthands/transitionObject.native.js +349 -0
- package/dist/cjs/shorthands/transitionObject.native.js.map +1 -0
- package/dist/cjs/tooling/candidate.cjs +254 -15
- package/dist/cjs/tooling/candidate.native.cjs +314 -62
- package/dist/cjs/tooling/candidate.native.js +314 -62
- package/dist/cjs/tooling/candidate.native.js.map +1 -1
- package/dist/cjs/tooling/config.cjs +19 -9
- package/dist/cjs/tooling/config.native.cjs +25 -26
- package/dist/cjs/tooling/config.native.js +25 -26
- package/dist/cjs/tooling/config.native.js.map +1 -1
- package/dist/cjs/tooling/registry.cjs +579 -11
- package/dist/cjs/tooling/registry.native.cjs +579 -11
- package/dist/cjs/tooling/registry.native.js +579 -11
- package/dist/cjs/tooling/registry.native.js.map +1 -1
- package/dist/cjs/tooling/toolingDiagnostics.cjs +306 -10
- package/dist/cjs/tooling/toolingDiagnostics.native.cjs +408 -48
- package/dist/cjs/tooling/toolingDiagnostics.native.js +408 -48
- package/dist/cjs/tooling/toolingDiagnostics.native.js.map +1 -1
- package/dist/cjs/tooling/toolingRegistry.cjs +6 -1
- package/dist/cjs/tooling/toolingRegistry.native.cjs +9 -1
- package/dist/cjs/tooling/toolingRegistry.native.js +9 -1
- package/dist/cjs/tooling/toolingRegistry.native.js.map +1 -1
- package/dist/cjs/tooling.cjs +1 -0
- package/dist/cjs/tooling.native.cjs +1 -0
- package/dist/cjs/tooling.native.js +1 -0
- package/dist/cjs/tooling.native.js.map +1 -1
- package/dist/cjs/transitions.cjs +38 -0
- package/dist/cjs/transitions.native.cjs +40 -0
- package/dist/cjs/transitions.native.js +42 -0
- package/dist/cjs/transitions.native.js.map +1 -0
- package/dist/esm/ast/payloadShape.mjs +45 -17
- package/dist/esm/ast/payloadShape.mjs.map +1 -1
- package/dist/esm/ast/payloadShape.native.js +45 -17
- package/dist/esm/ast/payloadShape.native.js.map +1 -1
- package/dist/esm/ast/resolvePayload.mjs +16 -9
- package/dist/esm/ast/resolvePayload.mjs.map +1 -1
- package/dist/esm/ast/resolvePayload.native.js +16 -9
- package/dist/esm/ast/resolvePayload.native.js.map +1 -1
- package/dist/esm/programs/lowerProgram.mjs +2 -2
- package/dist/esm/programs/lowerProgram.mjs.map +1 -1
- package/dist/esm/programs/lowerProgram.native.js +2 -2
- package/dist/esm/programs/lowerProgram.native.js.map +1 -1
- package/dist/esm/runtime/clauseIdentity.mjs +2 -22
- package/dist/esm/runtime/clauseIdentity.mjs.map +1 -1
- package/dist/esm/runtime/clauseIdentity.native.js +2 -22
- package/dist/esm/runtime/clauseIdentity.native.js.map +1 -1
- package/dist/esm/runtime/clausePrecedence.mjs +2 -2
- package/dist/esm/runtime/clausePrecedence.mjs.map +1 -1
- package/dist/esm/runtime/clausePrecedence.native.js +3 -10
- package/dist/esm/runtime/clausePrecedence.native.js.map +1 -1
- package/dist/esm/runtime/modifierVocabulary.native.js +1 -8
- package/dist/esm/runtime/modifierVocabulary.native.js.map +1 -1
- package/dist/esm/runtime/scanFlatValue.mjs +59 -7
- package/dist/esm/runtime/scanFlatValue.mjs.map +1 -1
- package/dist/esm/runtime/scanFlatValue.native.js +59 -7
- package/dist/esm/runtime/scanFlatValue.native.js.map +1 -1
- package/dist/esm/runtime/spring.mjs +93 -0
- package/dist/esm/runtime/spring.mjs.map +1 -0
- package/dist/esm/runtime/spring.native.js +99 -0
- package/dist/esm/runtime/spring.native.js.map +1 -0
- package/dist/esm/runtime/stateModifiers.mjs +22 -2
- package/dist/esm/runtime/stateModifiers.mjs.map +1 -1
- package/dist/esm/runtime/stateModifiers.native.js +22 -2
- package/dist/esm/runtime/stateModifiers.native.js.map +1 -1
- package/dist/esm/runtime/tokenCategories.mjs +3 -0
- package/dist/esm/runtime/tokenCategories.mjs.map +1 -1
- package/dist/esm/runtime/tokenCategories.native.js +3 -0
- package/dist/esm/runtime/tokenCategories.native.js.map +1 -1
- package/dist/esm/runtime/unitlessNumbers.mjs +0 -5
- package/dist/esm/runtime/unitlessNumbers.mjs.map +1 -1
- package/dist/esm/runtime/unitlessNumbers.native.js +0 -5
- package/dist/esm/runtime/unitlessNumbers.native.js.map +1 -1
- package/dist/esm/runtime.mjs +4 -2
- package/dist/esm/runtime.native.js +4 -2
- package/dist/esm/shorthands/transition.mjs +111 -36
- package/dist/esm/shorthands/transition.mjs.map +1 -1
- package/dist/esm/shorthands/transition.native.js +113 -36
- package/dist/esm/shorthands/transition.native.js.map +1 -1
- package/dist/esm/shorthands/transitionAlign.mjs +13 -10
- package/dist/esm/shorthands/transitionAlign.mjs.map +1 -1
- package/dist/esm/shorthands/transitionAlign.native.js +14 -11
- package/dist/esm/shorthands/transitionAlign.native.js.map +1 -1
- package/dist/esm/shorthands/transitionLegacy.mjs +260 -126
- package/dist/esm/shorthands/transitionLegacy.mjs.map +1 -1
- package/dist/esm/shorthands/transitionLegacy.native.js +330 -155
- package/dist/esm/shorthands/transitionLegacy.native.js.map +1 -1
- package/dist/esm/shorthands/transitionNative.mjs +5 -5
- package/dist/esm/shorthands/transitionNative.mjs.map +1 -1
- package/dist/esm/shorthands/transitionNative.native.js +8 -7
- package/dist/esm/shorthands/transitionNative.native.js.map +1 -1
- package/dist/esm/shorthands/transitionObject.mjs +280 -0
- package/dist/esm/shorthands/transitionObject.mjs.map +1 -0
- package/dist/esm/shorthands/transitionObject.native.js +323 -0
- package/dist/esm/shorthands/transitionObject.native.js.map +1 -0
- package/dist/esm/tooling/candidate.mjs +250 -16
- package/dist/esm/tooling/candidate.mjs.map +1 -1
- package/dist/esm/tooling/candidate.native.js +310 -63
- package/dist/esm/tooling/candidate.native.js.map +1 -1
- package/dist/esm/tooling/config.mjs +18 -9
- package/dist/esm/tooling/config.mjs.map +1 -1
- package/dist/esm/tooling/config.native.js +24 -26
- package/dist/esm/tooling/config.native.js.map +1 -1
- package/dist/esm/tooling/registry.mjs +579 -11
- package/dist/esm/tooling/registry.mjs.map +1 -1
- package/dist/esm/tooling/registry.native.js +579 -11
- package/dist/esm/tooling/registry.native.js.map +1 -1
- package/dist/esm/tooling/toolingDiagnostics.mjs +306 -11
- package/dist/esm/tooling/toolingDiagnostics.mjs.map +1 -1
- package/dist/esm/tooling/toolingDiagnostics.native.js +408 -49
- package/dist/esm/tooling/toolingDiagnostics.native.js.map +1 -1
- package/dist/esm/tooling/toolingRegistry.mjs +6 -1
- package/dist/esm/tooling/toolingRegistry.mjs.map +1 -1
- package/dist/esm/tooling/toolingRegistry.native.js +9 -1
- package/dist/esm/tooling/toolingRegistry.native.js.map +1 -1
- package/dist/esm/tooling.mjs +2 -0
- package/dist/esm/tooling.native.js +2 -0
- package/dist/esm/transitions.mjs +5 -0
- package/dist/esm/transitions.native.js +5 -0
- package/package.json +21 -3
- package/src/ast/payloadShape.ts +44 -16
- package/src/ast/resolvePayload.ts +28 -13
- package/src/programs/lowerProgram.ts +9 -4
- package/src/runtime/clauseIdentity.ts +8 -31
- package/src/runtime/clausePrecedence.ts +2 -10
- package/src/runtime/scanFlatValue.ts +81 -9
- package/src/runtime/spring.ts +208 -0
- package/src/runtime/stateModifiers.ts +31 -1
- package/src/runtime/tokenCategories.ts +3 -0
- package/src/runtime/unitlessNumbers.ts +0 -5
- package/src/runtime.ts +13 -0
- package/src/shorthands/transition.ts +159 -44
- package/src/shorthands/transitionAlign.ts +22 -12
- package/src/shorthands/transitionLegacy.ts +376 -156
- package/src/shorthands/transitionNative.ts +8 -11
- package/src/shorthands/transitionObject.ts +369 -0
- package/src/tooling/candidate.ts +269 -14
- package/src/tooling/config.ts +25 -9
- package/src/tooling/registry.ts +339 -12
- package/src/tooling/toolingDiagnostics.ts +474 -9
- package/src/tooling/toolingRegistry.ts +6 -1
- package/src/tooling.ts +1 -0
- package/src/transitions.ts +42 -0
- package/types/ast/payloadShape.d.ts.map +2 -2
- package/types/ast/resolvePayload.d.ts +5 -4
- package/types/ast/resolvePayload.d.ts.map +2 -2
- package/types/programs/lowerProgram.d.ts +4 -2
- package/types/programs/lowerProgram.d.ts.map +2 -2
- package/types/runtime/clauseIdentity.d.ts +1 -4
- package/types/runtime/clauseIdentity.d.ts.map +2 -2
- package/types/runtime/clausePrecedence.d.ts.map +2 -2
- package/types/runtime/scanFlatValue.d.ts +1 -1
- package/types/runtime/scanFlatValue.d.ts.map +2 -2
- package/types/runtime/spring.d.ts +61 -0
- package/types/runtime/spring.d.ts.map +11 -0
- package/types/runtime/stateModifiers.d.ts +4 -0
- package/types/runtime/stateModifiers.d.ts.map +2 -2
- package/types/runtime/tokenCategories.d.ts.map +2 -2
- package/types/runtime/unitlessNumbers.d.ts.map +2 -2
- package/types/runtime.d.ts +3 -1
- package/types/runtime.d.ts.map +2 -2
- package/types/shorthands/transition.d.ts +26 -5
- package/types/shorthands/transition.d.ts.map +2 -2
- package/types/shorthands/transitionAlign.d.ts.map +2 -2
- package/types/shorthands/transitionLegacy.d.ts +19 -4
- package/types/shorthands/transitionLegacy.d.ts.map +2 -2
- package/types/shorthands/transitionNative.d.ts.map +1 -1
- package/types/shorthands/transitionObject.d.ts +49 -0
- package/types/shorthands/transitionObject.d.ts.map +11 -0
- package/types/tooling/candidate.d.ts +13 -0
- package/types/tooling/candidate.d.ts.map +2 -2
- package/types/tooling/config.d.ts +8 -1
- package/types/tooling/config.d.ts.map +2 -2
- package/types/tooling/registry.d.ts +4 -2
- package/types/tooling/registry.d.ts.map +2 -2
- package/types/tooling/toolingDiagnostics.d.ts +3 -1
- package/types/tooling/toolingDiagnostics.d.ts.map +2 -2
- package/types/tooling/toolingRegistry.d.ts.map +2 -2
- package/types/tooling.d.ts +1 -0
- package/types/tooling.d.ts.map +2 -2
- package/types/transitions.d.ts +5 -0
- 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
|
+
}
|