@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
package/src/tooling/candidate.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { namedCssColors } from '../runtime/namedCssColors'
|
|
2
|
+
import { propTokenGroupFallbacks } from './config'
|
|
2
3
|
import {
|
|
3
4
|
grammarEntries,
|
|
4
5
|
fontWeightNames,
|
|
5
6
|
insetAxisProps,
|
|
6
7
|
prefixToEntries,
|
|
8
|
+
propToGrammarEntry,
|
|
7
9
|
radiusCornerProps,
|
|
8
10
|
sizeUtilityProps,
|
|
9
11
|
standaloneValueProps,
|
|
@@ -62,9 +64,42 @@ export type CandidateClassification =
|
|
|
62
64
|
| { kind: 'tamagui'; parsed: ParsedCandidate }
|
|
63
65
|
| { kind: 'passthrough'; reason: string }
|
|
64
66
|
|
|
65
|
-
const sizingConveniences = new Set([
|
|
67
|
+
const sizingConveniences = new Set([
|
|
68
|
+
'full',
|
|
69
|
+
'auto',
|
|
70
|
+
'screen',
|
|
71
|
+
'dvh',
|
|
72
|
+
'lvh',
|
|
73
|
+
'svh',
|
|
74
|
+
'dvw',
|
|
75
|
+
'lvw',
|
|
76
|
+
'svw',
|
|
77
|
+
'min',
|
|
78
|
+
'max',
|
|
79
|
+
'fit',
|
|
80
|
+
])
|
|
66
81
|
const fontGenerics = new Set(['sans', 'serif', 'mono'])
|
|
67
82
|
const numericPattern = /^\d+(?:\.\d+)?$/
|
|
83
|
+
|
|
84
|
+
// tailwind v4's named leading scale, as unitless line-height ratios
|
|
85
|
+
export const tailwindLeadingRatios: Record<string, number> = {
|
|
86
|
+
none: 1,
|
|
87
|
+
tight: 1.25,
|
|
88
|
+
snug: 1.375,
|
|
89
|
+
normal: 1.5,
|
|
90
|
+
relaxed: 1.625,
|
|
91
|
+
loose: 2,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// tailwind v4's named tracking scale, in em of the element's font size
|
|
95
|
+
export const tailwindTrackingEms: Record<string, number> = {
|
|
96
|
+
tighter: -0.05,
|
|
97
|
+
tight: -0.025,
|
|
98
|
+
normal: 0,
|
|
99
|
+
wide: 0.025,
|
|
100
|
+
wider: 0.05,
|
|
101
|
+
widest: 0.1,
|
|
102
|
+
}
|
|
68
103
|
const extraPrefixes = [
|
|
69
104
|
'border-x',
|
|
70
105
|
'border-y',
|
|
@@ -72,9 +107,12 @@ const extraPrefixes = [
|
|
|
72
107
|
'rounded-r',
|
|
73
108
|
'rounded-b',
|
|
74
109
|
'rounded-l',
|
|
110
|
+
'rounded-s',
|
|
111
|
+
'rounded-e',
|
|
75
112
|
'inset-x',
|
|
76
113
|
'inset-y',
|
|
77
114
|
'size',
|
|
115
|
+
'translate',
|
|
78
116
|
]
|
|
79
117
|
const negativeTokenProps = new Set([
|
|
80
118
|
'margin',
|
|
@@ -82,6 +120,10 @@ const negativeTokenProps = new Set([
|
|
|
82
120
|
'marginRight',
|
|
83
121
|
'marginBottom',
|
|
84
122
|
'marginLeft',
|
|
123
|
+
'marginInlineStart',
|
|
124
|
+
'marginInlineEnd',
|
|
125
|
+
'marginBlockStart',
|
|
126
|
+
'marginBlockEnd',
|
|
85
127
|
'marginHorizontal',
|
|
86
128
|
'marginVertical',
|
|
87
129
|
'top',
|
|
@@ -89,9 +131,53 @@ const negativeTokenProps = new Set([
|
|
|
89
131
|
'bottom',
|
|
90
132
|
'left',
|
|
91
133
|
'inset',
|
|
134
|
+
'insetInlineStart',
|
|
135
|
+
'insetInlineEnd',
|
|
136
|
+
'insetBlockStart',
|
|
137
|
+
'insetBlockEnd',
|
|
138
|
+
'start',
|
|
139
|
+
'end',
|
|
140
|
+
'zIndex',
|
|
92
141
|
'x',
|
|
93
142
|
'y',
|
|
143
|
+
'rotate',
|
|
144
|
+
'rotateX',
|
|
145
|
+
'rotateY',
|
|
146
|
+
'rotateZ',
|
|
147
|
+
'skewX',
|
|
148
|
+
'skewY',
|
|
149
|
+
'order',
|
|
150
|
+
'scale',
|
|
151
|
+
'scaleX',
|
|
152
|
+
'scaleY',
|
|
94
153
|
'letterSpacing',
|
|
154
|
+
'outlineOffset',
|
|
155
|
+
])
|
|
156
|
+
const positionSpaceProps = new Set([
|
|
157
|
+
'top',
|
|
158
|
+
'right',
|
|
159
|
+
'bottom',
|
|
160
|
+
'left',
|
|
161
|
+
'inset',
|
|
162
|
+
'insetInlineStart',
|
|
163
|
+
'insetInlineEnd',
|
|
164
|
+
'insetBlockStart',
|
|
165
|
+
'insetBlockEnd',
|
|
166
|
+
'start',
|
|
167
|
+
'end',
|
|
168
|
+
])
|
|
169
|
+
const marginSpaceProps = new Set([
|
|
170
|
+
'margin',
|
|
171
|
+
'marginTop',
|
|
172
|
+
'marginRight',
|
|
173
|
+
'marginBottom',
|
|
174
|
+
'marginLeft',
|
|
175
|
+
'marginInlineStart',
|
|
176
|
+
'marginInlineEnd',
|
|
177
|
+
'marginBlockStart',
|
|
178
|
+
'marginBlockEnd',
|
|
179
|
+
'marginHorizontal',
|
|
180
|
+
'marginVertical',
|
|
95
181
|
])
|
|
96
182
|
const borderWidthKeywords = new Set(['thin', 'medium', 'thick'])
|
|
97
183
|
const ambiguousCssKeywords = new Set([
|
|
@@ -123,7 +209,14 @@ function hasName(names: Names | undefined, name: string): boolean {
|
|
|
123
209
|
return name in names
|
|
124
210
|
}
|
|
125
211
|
|
|
126
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Split a candidate on its unbracketed colons: everything before the last one is a
|
|
214
|
+
* raw modifier, the remainder is the base. `null` for unbalanced brackets or an
|
|
215
|
+
* empty base, which are not candidates at all.
|
|
216
|
+
*/
|
|
217
|
+
export function splitCandidate(
|
|
218
|
+
candidate: string
|
|
219
|
+
): { modifiers: string[]; base: string } | null {
|
|
127
220
|
const parts: string[] = []
|
|
128
221
|
let current = ''
|
|
129
222
|
let bracketDepth = 0
|
|
@@ -198,8 +291,19 @@ function normalizeModifiers(
|
|
|
198
291
|
return normalized
|
|
199
292
|
}
|
|
200
293
|
|
|
294
|
+
function tokenDomain(
|
|
295
|
+
config: GrammarConfigView,
|
|
296
|
+
category: TokenCategory
|
|
297
|
+
): Names | undefined {
|
|
298
|
+
const fallback = propTokenGroupFallbacks[category]
|
|
299
|
+
return (
|
|
300
|
+
config.tokenNames?.[category] ||
|
|
301
|
+
(fallback ? config.tokenNames?.[fallback] : undefined)
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
201
305
|
function hasTokenDomain(config: GrammarConfigView, category: TokenCategory): boolean {
|
|
202
|
-
return config
|
|
306
|
+
return tokenDomain(config, category) !== undefined
|
|
203
307
|
}
|
|
204
308
|
|
|
205
309
|
export function hasTokenName(
|
|
@@ -207,7 +311,24 @@ export function hasTokenName(
|
|
|
207
311
|
category: TokenCategory,
|
|
208
312
|
name: string
|
|
209
313
|
): boolean {
|
|
210
|
-
return
|
|
314
|
+
return resolveTokenName(config, category, name) !== null
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Tailwind spells half-steps as `0.5`; some Tamagui configs use `0-5`.
|
|
318
|
+
export function decimalHalfTokenAlias(name: string): string | null {
|
|
319
|
+
const match = /^(-?\d+)\.5$/.exec(name)
|
|
320
|
+
return match ? `${match[1]}-5` : null
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function resolveTokenName(
|
|
324
|
+
config: GrammarConfigView,
|
|
325
|
+
category: TokenCategory,
|
|
326
|
+
name: string
|
|
327
|
+
): string | null {
|
|
328
|
+
const names = tokenDomain(config, category)
|
|
329
|
+
if (hasName(names, name)) return name
|
|
330
|
+
const alias = decimalHalfTokenAlias(name)
|
|
331
|
+
return alias !== null && hasName(names, alias) ? alias : null
|
|
211
332
|
}
|
|
212
333
|
|
|
213
334
|
function entriesForProps(props: readonly string[]): GrammarEntry[] {
|
|
@@ -236,11 +357,17 @@ function resolveEntries(
|
|
|
236
357
|
)
|
|
237
358
|
}
|
|
238
359
|
if (prefix === 'size') {
|
|
239
|
-
return entriesForProps(sizeUtilityProps)
|
|
360
|
+
return entriesForProps(sizeUtilityProps).map((entry) => ({
|
|
361
|
+
...entry,
|
|
362
|
+
tokenCategory: 'size',
|
|
363
|
+
}))
|
|
240
364
|
}
|
|
241
365
|
if (prefix === 'inset-x' || prefix === 'inset-y') {
|
|
242
366
|
return entriesForProps(insetAxisProps[prefix.slice('inset-'.length)])
|
|
243
367
|
}
|
|
368
|
+
if (prefix === 'translate') {
|
|
369
|
+
return entriesForProps(['x', 'y'])
|
|
370
|
+
}
|
|
244
371
|
if (prefix.startsWith('rounded-')) {
|
|
245
372
|
const props = radiusCornerProps[prefix.slice('rounded-'.length)]
|
|
246
373
|
return props ? entriesForProps(props) : []
|
|
@@ -329,6 +456,10 @@ function arbitraryTextKind(value: string): 'fontSize' | 'color' | null {
|
|
|
329
456
|
return null
|
|
330
457
|
}
|
|
331
458
|
|
|
459
|
+
function isWidthColorPrefix(prefix: string): boolean {
|
|
460
|
+
return prefix.startsWith('border') || prefix === 'outline'
|
|
461
|
+
}
|
|
462
|
+
|
|
332
463
|
function arbitraryBorderKind(value: string): 'width' | 'color' | null {
|
|
333
464
|
if (/^-?(?:\d+|\d*\.\d+)$/.test(value)) return 'width'
|
|
334
465
|
if (cssLengthPattern.test(value) || borderWidthKeywords.has(value)) return 'width'
|
|
@@ -379,7 +510,7 @@ function chooseEntry(
|
|
|
379
510
|
const arbitrary = arbitraryInner(rawValue)
|
|
380
511
|
if (arbitrary !== null) {
|
|
381
512
|
if (!arbitrary) return null
|
|
382
|
-
if (prefix
|
|
513
|
+
if (isWidthColorPrefix(prefix)) {
|
|
383
514
|
const width = entries.find((entry) => entry.prop.endsWith('Width'))
|
|
384
515
|
const color = entries.find((entry) => entry.prop.endsWith('Color'))
|
|
385
516
|
const kind = arbitraryBorderKind(decodeArbitrary(arbitrary))
|
|
@@ -422,6 +553,9 @@ function chooseEntry(
|
|
|
422
553
|
}
|
|
423
554
|
}
|
|
424
555
|
const color = entries.find((entry) => entry.prop === 'color')
|
|
556
|
+
if (color && rawValue === 'transparent') {
|
|
557
|
+
return { entry: color, valueKind: 'enum' }
|
|
558
|
+
}
|
|
425
559
|
const colorName = tokenLookupName('color', rawValue)
|
|
426
560
|
if (color && hasTokenName(config, 'color', colorName)) {
|
|
427
561
|
return { entry: color, valueKind: 'token' }
|
|
@@ -449,11 +583,12 @@ function chooseEntry(
|
|
|
449
583
|
: null
|
|
450
584
|
}
|
|
451
585
|
|
|
452
|
-
if (prefix
|
|
586
|
+
if (isWidthColorPrefix(prefix)) {
|
|
453
587
|
const width = entries.find((entry) => entry.prop.endsWith('Width'))
|
|
454
588
|
const color = entries.find((entry) => entry.prop.endsWith('Color'))
|
|
455
589
|
const token = negative ? `-${rawValue}` : rawValue
|
|
456
|
-
const
|
|
590
|
+
const widthCategory = width?.tokenCategory || 'space'
|
|
591
|
+
const matchesWidth = width && hasTokenName(config, widthCategory, token)
|
|
457
592
|
const colorName = tokenLookupName('color', rawValue)
|
|
458
593
|
const matchesColor = color && hasTokenName(config, 'color', colorName)
|
|
459
594
|
if (matchesWidth && matchesColor) return null
|
|
@@ -463,28 +598,134 @@ function chooseEntry(
|
|
|
463
598
|
if (matchesColor) {
|
|
464
599
|
return { entry: color, valueKind: 'token' }
|
|
465
600
|
}
|
|
601
|
+
if (color && rawValue === 'transparent') {
|
|
602
|
+
return { entry: color, valueKind: 'enum' }
|
|
603
|
+
}
|
|
466
604
|
return null
|
|
467
605
|
}
|
|
468
606
|
|
|
607
|
+
if (prefix === 'flex' && fractionIsValid(rawValue)) {
|
|
608
|
+
const flex = entries.find((entry) => entry.prop === 'flex')
|
|
609
|
+
if (flex) {
|
|
610
|
+
return { entry: flex, valueKind: 'convenience', convenience: 'flex-bundle' }
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (prefix === 'tracking' && Object.hasOwn(tailwindTrackingEms, rawValue)) {
|
|
615
|
+
const letterSpacing = entries.find((entry) => entry.prop === 'letterSpacing')
|
|
616
|
+
if (letterSpacing) {
|
|
617
|
+
return {
|
|
618
|
+
entry: letterSpacing,
|
|
619
|
+
valueKind: 'convenience',
|
|
620
|
+
convenience: 'tracking-keyword',
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (prefix === 'leading' && Object.hasOwn(tailwindLeadingRatios, rawValue)) {
|
|
626
|
+
const lineHeight = entries.find((entry) => entry.prop === 'lineHeight')
|
|
627
|
+
if (lineHeight) {
|
|
628
|
+
return {
|
|
629
|
+
entry: lineHeight,
|
|
630
|
+
valueKind: 'convenience',
|
|
631
|
+
convenience: 'leading-keyword',
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (numericPattern.test(rawValue)) {
|
|
637
|
+
const angle = entries.find((entry) => entry.conveniences?.includes('angle'))
|
|
638
|
+
if (angle) {
|
|
639
|
+
return { entry: angle, valueKind: 'convenience', convenience: 'angle' }
|
|
640
|
+
}
|
|
641
|
+
if (prefix === 'flex') {
|
|
642
|
+
const flex = entries.find((entry) => entry.prop === 'flex')
|
|
643
|
+
if (flex)
|
|
644
|
+
return { entry: flex, valueKind: 'convenience', convenience: 'flex-bundle' }
|
|
645
|
+
}
|
|
646
|
+
if (prefix === 'grow') {
|
|
647
|
+
const grow = entries.find((entry) => entry.prop === 'flexGrow')
|
|
648
|
+
if (grow) return { entry: grow, valueKind: 'convenience', convenience: 'integer' }
|
|
649
|
+
}
|
|
650
|
+
if (prefix === 'shrink') {
|
|
651
|
+
const shrink = entries.find((entry) => entry.prop === 'flexShrink')
|
|
652
|
+
if (shrink)
|
|
653
|
+
return { entry: shrink, valueKind: 'convenience', convenience: 'integer' }
|
|
654
|
+
}
|
|
655
|
+
if (prefix === 'line-clamp') {
|
|
656
|
+
const clamp = entries.find((entry) => entry.prop === 'numberOfLines')
|
|
657
|
+
if (clamp) return { entry: clamp, valueKind: 'convenience', convenience: 'integer' }
|
|
658
|
+
}
|
|
659
|
+
if (prefix === 'leading') {
|
|
660
|
+
const lineHeight = entries.find((entry) => entry.prop === 'lineHeight')
|
|
661
|
+
if (
|
|
662
|
+
lineHeight &&
|
|
663
|
+
(!lineHeight.tokenCategory ||
|
|
664
|
+
!hasTokenName(config, lineHeight.tokenCategory, rawValue))
|
|
665
|
+
) {
|
|
666
|
+
return {
|
|
667
|
+
entry: lineHeight,
|
|
668
|
+
valueKind: 'convenience',
|
|
669
|
+
convenience: 'integer',
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
// grid utilities: grid-cols-3, col-span-2, col-start-1, row-span-3, etc.
|
|
674
|
+
if (
|
|
675
|
+
prefix === 'grid-cols' ||
|
|
676
|
+
prefix === 'col-span' ||
|
|
677
|
+
prefix === 'col-start' ||
|
|
678
|
+
prefix === 'col-end' ||
|
|
679
|
+
prefix === 'row-span' ||
|
|
680
|
+
prefix === 'row-start' ||
|
|
681
|
+
prefix === 'row-end'
|
|
682
|
+
) {
|
|
683
|
+
const entry = entries[0]
|
|
684
|
+
if (entry) return { entry, valueKind: 'convenience', convenience: 'integer' }
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
469
688
|
for (const entry of entries) {
|
|
470
689
|
if (entry.tokenCategory) {
|
|
471
|
-
|
|
690
|
+
if (entry.tokenCategory === 'color' && rawValue === 'transparent') {
|
|
691
|
+
return { entry, valueKind: 'enum' }
|
|
692
|
+
}
|
|
693
|
+
if (entry.tokenCategory === 'radius' && rawValue === 'none') {
|
|
694
|
+
return { entry, valueKind: 'convenience', convenience: 'zero' }
|
|
695
|
+
}
|
|
696
|
+
// Negative zero has the same runtime value as zero. Tailwind emits these
|
|
697
|
+
// candidates, while token maps intentionally do not duplicate a `-0` key.
|
|
698
|
+
const name = negative && rawValue !== '0' ? `-${rawValue}` : rawValue
|
|
472
699
|
const tokenName = tokenLookupName(entry.tokenCategory, name)
|
|
473
700
|
if (hasTokenName(config, entry.tokenCategory, tokenName)) {
|
|
474
701
|
return { entry, valueKind: 'token' }
|
|
475
702
|
}
|
|
476
703
|
if (
|
|
477
|
-
entry.
|
|
704
|
+
entry.conveniences?.includes('sizing-keyword') &&
|
|
478
705
|
(sizingConveniences.has(rawValue) || fractionIsValid(rawValue))
|
|
479
706
|
) {
|
|
480
707
|
return { entry, valueKind: 'convenience', convenience: 'sizing-keyword' }
|
|
481
708
|
}
|
|
709
|
+
if (
|
|
710
|
+
positionSpaceProps.has(entry.prop) &&
|
|
711
|
+
(rawValue === 'full' || rawValue === 'auto' || fractionIsValid(rawValue))
|
|
712
|
+
) {
|
|
713
|
+
return { entry, valueKind: 'convenience', convenience: 'sizing-keyword' }
|
|
714
|
+
}
|
|
715
|
+
if (marginSpaceProps.has(entry.prop) && rawValue === 'auto') {
|
|
716
|
+
return { entry, valueKind: 'convenience', convenience: 'sizing-keyword' }
|
|
717
|
+
}
|
|
482
718
|
if (entry.tokenCategory === 'zIndex' && numericPattern.test(rawValue)) {
|
|
483
719
|
return { entry, valueKind: 'convenience', convenience: 'integer' }
|
|
484
720
|
}
|
|
485
721
|
continue
|
|
486
722
|
}
|
|
487
|
-
if (
|
|
723
|
+
if (
|
|
724
|
+
prefix === 'opacity' ||
|
|
725
|
+
prefix === 'scale' ||
|
|
726
|
+
prefix === 'scale-x' ||
|
|
727
|
+
prefix === 'scale-y'
|
|
728
|
+
) {
|
|
488
729
|
if (numericPattern.test(rawValue)) {
|
|
489
730
|
return { entry, valueKind: 'convenience', convenience: 'percentage' }
|
|
490
731
|
}
|
|
@@ -493,6 +734,9 @@ function chooseEntry(
|
|
|
493
734
|
if (entry.prop === 'zIndex' && numericPattern.test(rawValue)) {
|
|
494
735
|
return { entry, valueKind: 'convenience', convenience: 'integer' }
|
|
495
736
|
}
|
|
737
|
+
if (entry.conveniences?.includes('integer') && numericPattern.test(rawValue)) {
|
|
738
|
+
return { entry, valueKind: 'convenience', convenience: 'integer' }
|
|
739
|
+
}
|
|
496
740
|
}
|
|
497
741
|
return null
|
|
498
742
|
}
|
|
@@ -524,7 +768,14 @@ export function parseCandidate(
|
|
|
524
768
|
if (
|
|
525
769
|
selected &&
|
|
526
770
|
(!negative ||
|
|
527
|
-
|
|
771
|
+
selected.convenience === 'tracking-keyword' ||
|
|
772
|
+
(negativeTokenProps.has(selected.entry.prop) &&
|
|
773
|
+
(selected.valueKind === 'token' ||
|
|
774
|
+
(selected.valueKind === 'arbitrary' && selected.entry.prop === 'order') ||
|
|
775
|
+
selected.convenience === 'angle' ||
|
|
776
|
+
selected.convenience === 'percentage' ||
|
|
777
|
+
selected.convenience === 'sizing-keyword' ||
|
|
778
|
+
selected.convenience === 'integer')))
|
|
528
779
|
) {
|
|
529
780
|
dynamic = { prefix, rawValue, selected }
|
|
530
781
|
// An exact configured token owns its spelling before a reserved whole utility. Other
|
|
@@ -549,7 +800,11 @@ export function parseCandidate(
|
|
|
549
800
|
}
|
|
550
801
|
|
|
551
802
|
const direct = wholeClassUtilities[split.base]
|
|
552
|
-
if (
|
|
803
|
+
if (
|
|
804
|
+
!negative &&
|
|
805
|
+
direct &&
|
|
806
|
+
(split.base !== 'shadow' || hasTokenName(config, 'boxShadow', 'sm'))
|
|
807
|
+
) {
|
|
553
808
|
const convenience = wholeClassConveniences[split.base]
|
|
554
809
|
return {
|
|
555
810
|
candidate,
|
|
@@ -621,7 +876,7 @@ export function formatCandidate(
|
|
|
621
876
|
{ prop, value, valueKind, modifiers = [] }: FormatCandidateInput,
|
|
622
877
|
config?: GrammarConfigView
|
|
623
878
|
): string | null {
|
|
624
|
-
const entry =
|
|
879
|
+
const entry = propToGrammarEntry[prop]
|
|
625
880
|
if (!entry) return null
|
|
626
881
|
if (valueKind === 'arbitrary' && value === '') return null
|
|
627
882
|
const normalizedModifiers = normalizeModifiers(modifiers, config || {})
|
package/src/tooling/config.ts
CHANGED
|
@@ -14,12 +14,7 @@ export type GrammarSourceConfig = {
|
|
|
14
14
|
shorthands?: Readonly<Record<string, string>>
|
|
15
15
|
media?: Names
|
|
16
16
|
themes?: Readonly<Record<string, unknown>>
|
|
17
|
-
tokensParsed?: Partial<
|
|
18
|
-
Record<
|
|
19
|
-
'space' | 'size' | 'radius' | 'zIndex' | 'color',
|
|
20
|
-
Readonly<Record<string, unknown>>
|
|
21
|
-
>
|
|
22
|
-
>
|
|
17
|
+
tokensParsed?: Partial<Record<string, Readonly<Record<string, unknown>>>>
|
|
23
18
|
fontsParsed?: Readonly<Record<string, GrammarFontConfig | undefined>>
|
|
24
19
|
}
|
|
25
20
|
|
|
@@ -98,6 +93,24 @@ function addNames(target: Set<string>, source: Names | undefined): void {
|
|
|
98
93
|
for (const key in source) target.add(key)
|
|
99
94
|
}
|
|
100
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Token groups named after one property. A config that defines the group binds
|
|
98
|
+
* the property to it; one that does not resolves the property through the
|
|
99
|
+
* fallback category, so legacy configs keep their classes.
|
|
100
|
+
*/
|
|
101
|
+
export const propTokenGroupFallbacks: Readonly<Record<string, TokenCategory>> = {
|
|
102
|
+
borderWidth: 'space',
|
|
103
|
+
outlineWidth: 'space',
|
|
104
|
+
outlineOffset: 'space',
|
|
105
|
+
width: 'size',
|
|
106
|
+
minWidth: 'size',
|
|
107
|
+
maxWidth: 'size',
|
|
108
|
+
inlineSize: 'size',
|
|
109
|
+
minInlineSize: 'size',
|
|
110
|
+
maxInlineSize: 'size',
|
|
111
|
+
flexBasis: 'size',
|
|
112
|
+
}
|
|
113
|
+
|
|
101
114
|
/**
|
|
102
115
|
* Creates the dependency-free config projection consumed by the shared style grammar.
|
|
103
116
|
* Runtime and compiler integrations must classify candidates through this same view so
|
|
@@ -107,7 +120,7 @@ export function createGrammarConfigView(
|
|
|
107
120
|
config: GrammarSourceConfig,
|
|
108
121
|
options: CreateGrammarConfigViewOptions = {}
|
|
109
122
|
): GrammarConfigView {
|
|
110
|
-
const tokenNames: Record<
|
|
123
|
+
const tokenNames: Record<string, Set<string>> = {
|
|
111
124
|
space: new Set(),
|
|
112
125
|
size: new Set(),
|
|
113
126
|
radius: new Set(),
|
|
@@ -120,8 +133,11 @@ export function createGrammarConfigView(
|
|
|
120
133
|
letterSpacing: new Set(),
|
|
121
134
|
}
|
|
122
135
|
|
|
123
|
-
for (const category
|
|
124
|
-
addNames(tokenNames[category], config.tokensParsed
|
|
136
|
+
for (const category in config.tokensParsed) {
|
|
137
|
+
addNames((tokenNames[category] ||= new Set()), config.tokensParsed[category])
|
|
138
|
+
}
|
|
139
|
+
for (const group in propTokenGroupFallbacks) {
|
|
140
|
+
tokenNames[group] ||= tokenNames[propTokenGroupFallbacks[group]]
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
for (const themeName in config.themes) {
|