@tamagui/codemod-flat-values 0.0.0-bootstrap.0 → 3.0.0-beta.1093.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +234 -1
  2. package/dist/builtInNames.mjs +14 -0
  3. package/dist/builtInNames.mjs.map +1 -0
  4. package/dist/containers.mjs +141 -0
  5. package/dist/containers.mjs.map +1 -0
  6. package/dist/convert.mjs +1233 -0
  7. package/dist/convert.mjs.map +1 -0
  8. package/dist/expressions.mjs +188 -0
  9. package/dist/expressions.mjs.map +1 -0
  10. package/dist/functionalVariants.mjs +469 -0
  11. package/dist/functionalVariants.mjs.map +1 -0
  12. package/dist/grammar.mjs +73 -0
  13. package/dist/grammar.mjs.map +1 -0
  14. package/dist/index.mjs +374 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/legacyConditions.mjs +293 -0
  17. package/dist/legacyConditions.mjs.map +1 -0
  18. package/dist/legacyNames.mjs +130 -0
  19. package/dist/legacyNames.mjs.map +1 -0
  20. package/dist/provenance.mjs +137 -0
  21. package/dist/provenance.mjs.map +1 -0
  22. package/dist/report.mjs +188 -0
  23. package/dist/report.mjs.map +1 -0
  24. package/dist/sheetAnatomy.mjs +200 -0
  25. package/dist/sheetAnatomy.mjs.map +1 -0
  26. package/dist/structuredNative.mjs +275 -0
  27. package/dist/structuredNative.mjs.map +1 -0
  28. package/dist/transition.mjs +257 -0
  29. package/dist/transition.mjs.map +1 -0
  30. package/package.json +35 -7
  31. package/src/builtInNames.ts +23 -0
  32. package/src/containers.ts +227 -0
  33. package/src/convert.ts +1977 -0
  34. package/src/expressions.ts +220 -0
  35. package/src/functionalVariants.ts +642 -0
  36. package/src/grammar.ts +190 -0
  37. package/src/index.ts +589 -0
  38. package/src/legacyConditions.ts +357 -0
  39. package/src/legacyNames.ts +160 -0
  40. package/src/provenance.ts +210 -0
  41. package/src/report.ts +362 -0
  42. package/src/sheetAnatomy.ts +277 -0
  43. package/src/structuredNative.ts +459 -0
  44. package/src/transition.ts +415 -0
package/src/grammar.ts ADDED
@@ -0,0 +1,190 @@
1
+ // Every piece of style knowledge the codemod needs comes from
2
+ // `@tamagui/style-grammar`: the value parser, the legacy condition converter, the
3
+ // clause merge, and the property/unit tables. Nothing here re-derives grammar
4
+ // behavior, so a converted program is spelled exactly the way the runtime and the
5
+ // compiler will read it back.
6
+
7
+ import { stylePropsAll } from '@tamagui/helpers'
8
+ import { shorthands } from '@tamagui/shorthands/v6'
9
+ import * as styleGrammarTooling from '@tamagui/style-grammar/tooling'
10
+ import type {
11
+ ConvertLegacyConditionOptions,
12
+ LegacyConditionError,
13
+ LegacyConditionResult,
14
+ } from './legacyConditions'
15
+ import type {
16
+ ConversionReason,
17
+ ConversionTargets,
18
+ HostView,
19
+ ModifierRegistryView,
20
+ ParsedClause,
21
+ ParsedValue,
22
+ } from '@tamagui/style-grammar/tooling'
23
+ import { replaceV6BuiltInTokens } from './builtInNames'
24
+ import {
25
+ convertLegacyConditionProp as convertLegacyConditionPropLocal,
26
+ pseudoToModifier,
27
+ } from './legacyConditions'
28
+
29
+ const grammar = styleGrammarTooling
30
+
31
+ export const {
32
+ assessFlatConversion,
33
+ createModifierRegistry,
34
+ defaultMediaKeys,
35
+ evaluateProgram,
36
+ expandToLonghands,
37
+ grammarEntries,
38
+ grammarPlatformNames,
39
+ legacyPartComposite,
40
+ mergeProgramValues,
41
+ parseValue,
42
+ programEligibility,
43
+ standaloneValueProps,
44
+ parseTransformString,
45
+ } = grammar
46
+
47
+ export { pseudoToModifier }
48
+
49
+ export type {
50
+ ConversionReason,
51
+ ConversionTargets,
52
+ HostView,
53
+ LegacyConditionError,
54
+ ModifierRegistryView,
55
+ ParsedClause,
56
+ ParsedValue,
57
+ }
58
+
59
+ export { shorthands }
60
+
61
+ function renameBuiltInTokens(value: unknown): unknown {
62
+ if (typeof value === 'string') return replaceV6BuiltInTokens(value)
63
+ if (Array.isArray(value)) return value.map(renameBuiltInTokens)
64
+ if (value === null || typeof value !== 'object') return value
65
+
66
+ const renamed: Record<string, unknown> = {}
67
+ for (const key in value) {
68
+ renamed[key] = renameBuiltInTokens((value as Record<string, unknown>)[key])
69
+ }
70
+ return renamed
71
+ }
72
+
73
+ export function convertLegacyConditionProp(
74
+ propName: string,
75
+ value: unknown,
76
+ options: ConvertLegacyConditionOptions
77
+ ): LegacyConditionResult | null {
78
+ return convertLegacyConditionPropLocal(propName, renameBuiltInTokens(value), options)
79
+ }
80
+
81
+ /** every prop spelling the codemod treats as carrying a style value */
82
+ export const styleProps: ReadonlySet<string> = new Set<string>([
83
+ ...grammarEntries.map((entry) => entry.prop),
84
+ ...Object.keys(standaloneValueProps),
85
+ ...Object.keys(stylePropsAll),
86
+ ...Object.keys(shorthands),
87
+ ...Object.values(shorthands),
88
+ ])
89
+
90
+ /**
91
+ * variant props whose values are size tokens. no program is built for them,
92
+ * but v3 reads the value as a size-scale key and a `$` spelling finds nothing
93
+ */
94
+ export const tokenVariantProps: ReadonlySet<string> = new Set<string>([
95
+ 'size',
96
+ 'elevation',
97
+ 'iconSize',
98
+ ])
99
+
100
+ /** the media keys of the V6 default config, plus the two motion queries */
101
+ export const codemodMediaNames: readonly string[] = [
102
+ ...defaultMediaKeys,
103
+ 'motionReduce',
104
+ 'motionSafe',
105
+ ]
106
+
107
+ export function resolveProp(prop: string): string {
108
+ return shorthands[prop] ?? prop
109
+ }
110
+
111
+ /**
112
+ * The one registered condition the codemod uses to reach the shared value
113
+ * converter for a single (prop, value) pair. Base values and clause payloads then
114
+ * spell identically by construction.
115
+ */
116
+ const payloadProbeCondition = '$platform-web'
117
+
118
+ export interface SharedPayload {
119
+ payload: string | null
120
+ errors: readonly LegacyConditionError[]
121
+ }
122
+
123
+ export function sharedPayload(
124
+ prop: string,
125
+ value: unknown,
126
+ registry: ModifierRegistryView
127
+ ): SharedPayload {
128
+ const converted = convertLegacyConditionProp(
129
+ payloadProbeCondition,
130
+ { [prop]: value },
131
+ { registry }
132
+ )
133
+ if (converted === null) {
134
+ throw new Error(
135
+ `the payload probe condition "${payloadProbeCondition}" is unregistered`
136
+ )
137
+ }
138
+ return {
139
+ payload: converted.contributions[0]?.clause.payload ?? null,
140
+ errors: converted.errors,
141
+ }
142
+ }
143
+
144
+ /**
145
+ * A property with no family split, no unit table entry, and no transform part, so
146
+ * the shared converter's answer for a string value is exactly its token rule and
147
+ * nothing else.
148
+ */
149
+ const stringProbeProp = 'color'
150
+
151
+ export interface FlatString {
152
+ /** the flat spelling, or null when the shared converter refused the value */
153
+ text: string | null
154
+ error: LegacyConditionError | null
155
+ }
156
+
157
+ /**
158
+ * The flat spelling of a legacy string, taken from the shared converter rather
159
+ * than re-derived. That converter drops `$` from token spellings anywhere in a
160
+ * composite value and refuses a value that mixes `$` with quoted or unquoted
161
+ * `url()` content, where a `$` is literal CSS the resolver never reads as a
162
+ * token candidate.
163
+ */
164
+ export function flatStringValue(
165
+ value: string,
166
+ registry: ModifierRegistryView
167
+ ): FlatString {
168
+ const probe = sharedPayload(stringProbeProp, value, registry)
169
+ return { text: probe.payload, error: probe.errors[0] ?? null }
170
+ }
171
+
172
+ const unitSuffixes = new Map<string, string>()
173
+
174
+ /**
175
+ * The unit a raw number carries for this property, taken from the shared
176
+ * converter itself: `px` for lengths, `deg` for `rotate`, nothing for the
177
+ * unitless table. A dynamic numeric expression interpolates with the same
178
+ * suffix a literal would have received.
179
+ */
180
+ export function unitSuffix(prop: string, registry: ModifierRegistryView): string {
181
+ const cached = unitSuffixes.get(prop)
182
+ if (cached !== undefined) return cached
183
+ const probe = sharedPayload(prop, 1, registry)
184
+ const suffix =
185
+ probe.payload !== null && probe.payload.startsWith('1') ? probe.payload.slice(1) : ''
186
+ unitSuffixes.set(prop, suffix)
187
+ return suffix
188
+ }
189
+
190
+ export const printProgram = grammar.formatParsedValue