@tamagui/static 1.0.1-beta.68 → 1.0.1-beta.69

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 (35) hide show
  1. package/dist/cjs/extractor/createEvaluator.js +1 -1
  2. package/dist/cjs/extractor/createEvaluator.js.map +2 -2
  3. package/dist/cjs/extractor/createExtractor.js +227 -115
  4. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  5. package/dist/cjs/extractor/extractToClassNames.js +16 -20
  6. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  7. package/dist/cjs/patchReactNativeWeb.js +29 -89
  8. package/dist/cjs/patchReactNativeWeb.js.map +2 -2
  9. package/dist/cjs/types.js.map +1 -1
  10. package/dist/esm/extractor/createEvaluator.js +1 -1
  11. package/dist/esm/extractor/createEvaluator.js.map +2 -2
  12. package/dist/esm/extractor/createExtractor.js +232 -119
  13. package/dist/esm/extractor/createExtractor.js.map +2 -2
  14. package/dist/esm/extractor/extractToClassNames.js +16 -20
  15. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  16. package/dist/esm/patchReactNativeWeb.js +29 -89
  17. package/dist/esm/patchReactNativeWeb.js.map +2 -2
  18. package/dist/jsx/extractor/createEvaluator.js +1 -1
  19. package/dist/jsx/extractor/createExtractor.js +232 -119
  20. package/dist/jsx/extractor/extractToClassNames.js +16 -20
  21. package/dist/jsx/patchReactNativeWeb.js +29 -89
  22. package/package.json +17 -12
  23. package/src/extractor/createEvaluator.ts +2 -1
  24. package/src/extractor/createExtractor.ts +356 -161
  25. package/src/extractor/extractToClassNames.ts +20 -31
  26. package/src/patchReactNativeWeb.ts +47 -96
  27. package/src/types.ts +6 -8
  28. package/types/extractor/createEvaluator.d.ts +1 -1
  29. package/types/extractor/createEvaluator.d.ts.map +1 -1
  30. package/types/extractor/createExtractor.d.ts +2 -1
  31. package/types/extractor/createExtractor.d.ts.map +1 -1
  32. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  33. package/types/patchReactNativeWeb.d.ts.map +1 -1
  34. package/types/types.d.ts +4 -7
  35. package/types/types.d.ts.map +1 -1
@@ -8,6 +8,7 @@ import {
8
8
  TamaguiInternalConfig,
9
9
  expandStyles,
10
10
  getSplitStyles,
11
+ getStylesAtomic,
11
12
  mediaQueryConfig,
12
13
  normalizeStyleObject,
13
14
  proxyThemeVariables,
@@ -82,6 +83,19 @@ export function createExtractor() {
82
83
  let loadedTamaguiConfig: TamaguiInternalConfig
83
84
  let hasLogged = false
84
85
 
86
+ function isValidStyleKey(name: string, staticConfig: StaticConfigParsed) {
87
+ return !!(
88
+ !!staticConfig.validStyles?.[name] ||
89
+ !!pseudos[name] ||
90
+ // disable variants because caching at the variant level = less work
91
+ // and expanding variants can get huge, i'm betting cost of many props
92
+ // is more than cost of expanding variants once for cache
93
+ // staticConfig.variants?.[name] ||
94
+ loadedTamaguiConfig.shorthands[name] ||
95
+ (name[0] === '$' ? !!mediaQueryConfig[name.slice(1)] : false)
96
+ )
97
+ }
98
+
85
99
  return {
86
100
  getTamagui() {
87
101
  return loadedTamaguiConfig
@@ -95,12 +109,14 @@ export function createExtractor() {
95
109
  shouldPrintDebug = false,
96
110
  sourcePath = '',
97
111
  onExtractTag,
112
+ onStyleRule,
98
113
  getFlattenedNode,
99
114
  disable,
100
115
  disableExtraction,
101
116
  disableExtractInlineMedia,
102
117
  disableExtractVariables,
103
118
  disableDebugAttr,
119
+ extractStyledDefinitions,
104
120
  prefixLogs,
105
121
  excludeProps,
106
122
  target,
@@ -177,8 +193,21 @@ export function createExtractor() {
177
193
 
178
194
  for (const bodyPath of body) {
179
195
  if (bodyPath.type !== 'ImportDeclaration') continue
180
- const node = ('node' in bodyPath ? bodyPath.node : bodyPath) as any
196
+ const node = ('node' in bodyPath ? bodyPath.node : bodyPath) as t.ImportDeclaration
181
197
  const from = node.source.value
198
+ // if importing styled()
199
+ if (extractStyledDefinitions) {
200
+ if (from === '@tamagui/core' || from === 'tamagui') {
201
+ if (
202
+ node.specifiers.some((specifier) => {
203
+ return specifier.local.name === 'styled'
204
+ })
205
+ ) {
206
+ doesUseValidImport = true
207
+ break
208
+ }
209
+ }
210
+ }
182
211
  const isValidImport = props.components.includes(from) || isInternalImport(from)
183
212
  if (isValidImport) {
184
213
  const isValidComponent = node.specifiers.some((specifier) => {
@@ -221,6 +250,7 @@ export function createExtractor() {
221
250
  let programPath: NodePath<t.Program>
222
251
 
223
252
  const res = {
253
+ styled: 0,
224
254
  flattened: 0,
225
255
  optimized: 0,
226
256
  modified: 0,
@@ -233,6 +263,138 @@ export function createExtractor() {
233
263
  programPath = path
234
264
  },
235
265
  },
266
+
267
+ CallExpression(path) {
268
+ if (disable || disableExtraction) {
269
+ return
270
+ }
271
+
272
+ if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== 'styled') {
273
+ return
274
+ }
275
+
276
+ const name =
277
+ t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id)
278
+ ? path.parent.id.name
279
+ : 'unknown'
280
+ const definition = path.node.arguments[1]
281
+
282
+ if (!name || !definition || !t.isObjectExpression(definition)) {
283
+ return
284
+ }
285
+
286
+ const Component = validComponents[name] as
287
+ | { staticConfig: StaticConfigParsed }
288
+ | undefined
289
+
290
+ if (!Component) {
291
+ if (shouldPrintDebug) {
292
+ console.log(
293
+ `Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`
294
+ )
295
+ }
296
+ return
297
+ }
298
+
299
+ const componentSkipProps = new Set([
300
+ ...(Component.staticConfig.inlineWhenUnflattened || []),
301
+ ...(Component.staticConfig.inlineProps || []),
302
+ ...(Component.staticConfig.deoptProps || []),
303
+ ])
304
+
305
+ // for now dont parse variants, spreads, etc
306
+ const skipped: (t.ObjectProperty | t.SpreadElement | t.ObjectMethod)[] = []
307
+ const styles = {}
308
+
309
+ // for now skip variants, will return to them
310
+ const skipProps = {
311
+ variants: true,
312
+ defaultVariants: true,
313
+ name: true,
314
+ }
315
+
316
+ // Generate scope object at this level
317
+ const staticNamespace = getStaticBindingsForScope(
318
+ path.scope,
319
+ importsWhitelist,
320
+ sourcePath,
321
+ bindingCache,
322
+ shouldPrintDebug
323
+ )
324
+
325
+ const attemptEval = !evaluateVars
326
+ ? evaluateAstNode
327
+ : createEvaluator({
328
+ tamaguiConfig,
329
+ staticNamespace,
330
+ sourcePath,
331
+ shouldPrintDebug,
332
+ })
333
+ const attemptEvalSafe = createSafeEvaluator(attemptEval)
334
+
335
+ for (const property of definition.properties) {
336
+ if (
337
+ !t.isObjectProperty(property) ||
338
+ !t.isIdentifier(property.key) ||
339
+ skipProps[property.key.name] ||
340
+ !isValidStyleKey(property.key.name, Component.staticConfig) ||
341
+ componentSkipProps.has(property.key.name)
342
+ ) {
343
+ skipped.push(property)
344
+ continue
345
+ }
346
+ // attempt eval
347
+ const out = attemptEvalSafe(property.value)
348
+ if (out === FAILED_EVAL) {
349
+ skipped.push(property)
350
+ } else {
351
+ styles[property.key.name] = out
352
+ }
353
+ }
354
+
355
+ // turn parsed styles into CSS
356
+ const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, {
357
+ focus: false,
358
+ hover: false,
359
+ mounted: false,
360
+ press: false,
361
+ pressIn: false,
362
+ resolveVariablesAs: 'variable',
363
+ })
364
+
365
+ const classNames = {
366
+ ...out.classNames,
367
+ }
368
+
369
+ // add in the style object as classnames
370
+ const atomics = getStylesAtomic(out.style)
371
+ for (const atomic of atomics) {
372
+ for (const rule of atomic.rules) {
373
+ out.rulesToInsert.push([atomic.identifier, rule])
374
+ }
375
+ classNames[atomic.property] = atomic.identifier
376
+ }
377
+
378
+ // leave only un-parsed props...
379
+ definition.properties = skipped
380
+
381
+ // ... + key: className
382
+ for (const cn in classNames) {
383
+ const val = classNames[cn]
384
+ definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)))
385
+ }
386
+
387
+ for (const [identifier, rule] of out.rulesToInsert) {
388
+ onStyleRule?.(identifier, [rule])
389
+ }
390
+
391
+ res.styled++
392
+
393
+ if (shouldPrintDebug) {
394
+ console.log(`Extracted styled(${name}) props:`, styles)
395
+ }
396
+ },
397
+
236
398
  JSXElement(traversePath) {
237
399
  tm.mark('jsx-element', shouldPrintDebug === 'verbose')
238
400
 
@@ -322,11 +484,10 @@ export function createExtractor() {
322
484
 
323
485
  const shouldLog = !hasLogged
324
486
  if (shouldLog) {
487
+ console.log(` 1️⃣ Inline optimized 2️⃣ Inline flattened 3️⃣ styled() extracted`)
325
488
  const prefix = ' |'
326
- console.log(
327
- prefixLogs || prefix,
328
- ' total · optimized · flattened '
329
- )
489
+ // prettier-ignore
490
+ console.log(prefixLogs || prefix, ' total · 1️⃣ · 2️⃣ · 3️⃣')
330
491
  hasLogged = true
331
492
  }
332
493
  if (disableExtraction) {
@@ -334,19 +495,10 @@ export function createExtractor() {
334
495
  }
335
496
 
336
497
  const { staticConfig } = component
498
+ const variants = staticConfig.variants || {}
337
499
  const isTextView = staticConfig.isText || false
338
500
  const validStyles = staticConfig?.validStyles ?? {}
339
501
 
340
- function isValidStyleKey(name: string) {
341
- return !!(
342
- !!validStyles[name] ||
343
- !!pseudos[name] ||
344
- staticConfig.variants?.[name] ||
345
- tamaguiConfig.shorthands[name] ||
346
- (name[0] === '$' ? !!mediaQueryConfig[name.slice(1)] : false)
347
- )
348
- }
349
-
350
502
  // find tag="a" tag="main" etc dom indicators
351
503
  let tagName = staticConfig.defaultProps?.tag ?? (isTextView ? 'span' : 'div')
352
504
  traversePath
@@ -389,7 +541,6 @@ export function createExtractor() {
389
541
  const attemptEval = !evaluateVars
390
542
  ? evaluateAstNode
391
543
  : createEvaluator({
392
- // @ts-ignore
393
544
  tamaguiConfig,
394
545
  staticNamespace,
395
546
  sourcePath,
@@ -471,38 +622,10 @@ export function createExtractor() {
471
622
  // set flattened
472
623
  node.attributes = flattenedAttrs
473
624
 
474
- // add in NON-STYLE default props
475
- if (staticConfig.defaultProps) {
476
- for (const key in staticConfig.defaultProps) {
477
- if (isValidStyleKey(key)) {
478
- continue
479
- }
480
- const serialize = require('babel-literal-to-ast')
481
- const val = staticConfig.defaultProps[key]
482
- try {
483
- const serializedDefaultProp = serialize(val)
484
- node.attributes.unshift(
485
- t.jsxAttribute(
486
- t.jsxIdentifier(key),
487
- typeof val === 'string'
488
- ? t.stringLiteral(val)
489
- : t.jsxExpressionContainer(serializedDefaultProp)
490
- )
491
- )
492
- } catch (err) {
493
- console.warn(
494
- `⚠️ Error evaluating default prop for component ${node.name.name}, prop ${key}\n error: ${err}\n value:`,
495
- val,
496
- '\n defaultProps:',
497
- staticConfig.defaultProps
498
- )
499
- }
500
- }
501
- }
502
-
503
625
  let attrs: ExtractedAttr[] = []
504
626
  let shouldDeopt = false
505
627
  const inlined = new Map<string, any>()
628
+ const variantValues = new Map<string, any>()
506
629
  let hasSetOptimized = false
507
630
  const inlineWhenUnflattenedOGVals = {}
508
631
 
@@ -727,50 +850,50 @@ export function createExtractor() {
727
850
 
728
851
  // never flatten if a prop isn't a valid static attribute
729
852
  // only post prop-mapping
730
- if (!isValidStyleKey(name)) {
853
+ if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
731
854
  let keys = [name]
732
855
  let out: any = null
733
- if (staticConfig.propMapper) {
734
- // for now passing empty props {}, a bit odd, need to at least document
735
- // for now we don't expose custom components so just noting behavior
736
- out = staticConfig.propMapper(
737
- name,
738
- styleValue,
739
- defaultTheme,
740
- staticConfig.defaultProps,
741
- { resolveVariablesAs: 'auto' },
742
- undefined,
743
- shouldPrintDebug
744
- )
745
- if (out) {
746
- if (!Array.isArray(out)) {
747
- console.warn(`Error expected array but got`, out)
748
- couldntParse = true
749
- shouldDeopt = true
750
- } else {
751
- out = Object.fromEntries(out)
752
- }
753
- }
754
- if (out) {
755
- if (isTargetingHTML) {
756
- // translate to DOM-compat
757
- out = rnw.createDOMProps(isTextView ? 'span' : 'div', out)
758
- // remove className - we dont use rnw styling
759
- delete out.className
760
- }
761
856
 
857
+ // for now passing empty props {}, a bit odd, need to at least document
858
+ // for now we don't expose custom components so just noting behavior
859
+ out = staticConfig.propMapper(
860
+ name,
861
+ styleValue,
862
+ defaultTheme,
863
+ staticConfig.defaultProps,
864
+ { resolveVariablesAs: 'auto' },
865
+ undefined,
866
+ shouldPrintDebug
867
+ )
868
+ if (out) {
869
+ if (!Array.isArray(out)) {
870
+ console.warn(`Error expected array but got`, out)
871
+ couldntParse = true
872
+ shouldDeopt = true
873
+ } else {
874
+ out = Object.fromEntries(out)
762
875
  keys = Object.keys(out)
763
876
  }
764
877
  }
878
+ if (out) {
879
+ if (isTargetingHTML) {
880
+ // translate to DOM-compat
881
+ out = rnw.createDOMProps(isTextView ? 'span' : 'div', out)
882
+ // remove className - we dont use rnw styling
883
+ delete out.className
884
+ }
885
+
886
+ keys = Object.keys(out)
887
+ }
765
888
 
766
889
  let didInline = false
767
890
  const attributes = keys.map((key) => {
768
891
  const val = out[key]
769
- if (isValidStyleKey(key)) {
892
+ if (isValidStyleKey(key, staticConfig)) {
770
893
  return {
771
894
  type: 'style',
772
- value: { [name]: styleValue },
773
- name,
895
+ value: { [key]: styleValue },
896
+ name: key,
774
897
  attr: path.node,
775
898
  } as const
776
899
  }
@@ -809,7 +932,7 @@ export function createExtractor() {
809
932
  inlineWhenUnflattenedOGVals[name] = { styleValue, attr }
810
933
  }
811
934
 
812
- if (isValidStyleKey(name)) {
935
+ if (isValidStyleKey(name, staticConfig)) {
813
936
  if (shouldPrintDebug) {
814
937
  console.log(` style: ${name} =`, styleValue)
815
938
  }
@@ -826,6 +949,9 @@ export function createExtractor() {
826
949
  attr: path.node,
827
950
  }
828
951
  } else {
952
+ if (variants[name]) {
953
+ variantValues.set(name, styleValue)
954
+ }
829
955
  inlined.set(name, true)
830
956
  return attr
831
957
  }
@@ -974,7 +1100,7 @@ export function createExtractor() {
974
1100
  return false
975
1101
  }
976
1102
  const propName = prop.key['name']
977
- if (!isValidStyleKey(propName) && propName !== 'tag') {
1103
+ if (!isValidStyleKey(propName, staticConfig) && propName !== 'tag') {
978
1104
  if (shouldPrintDebug) {
979
1105
  console.log(' not a valid style prop!', propName)
980
1106
  }
@@ -1148,9 +1274,14 @@ export function createExtractor() {
1148
1274
 
1149
1275
  let themeVal = inlined.get('theme')
1150
1276
  inlined.delete('theme')
1151
- const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k])
1152
- const shouldWrapThme = allOtherPropsExtractable && !!themeVal
1153
- const canFlattenProps = inlined.size === 0 || shouldWrapThme || allOtherPropsExtractable
1277
+
1278
+ for (const [key] of [...inlined]) {
1279
+ if (INLINE_EXTRACTABLE[key] || staticConfig.variants?.[key]) {
1280
+ inlined.delete(key)
1281
+ }
1282
+ }
1283
+
1284
+ const canFlattenProps = inlined.size === 0
1154
1285
 
1155
1286
  let shouldFlatten =
1156
1287
  !shouldDeopt &&
@@ -1159,6 +1290,8 @@ export function createExtractor() {
1159
1290
  staticConfig.neverFlatten !== true &&
1160
1291
  (staticConfig.neverFlatten === 'jsx' ? hasOnlyStringChildren : true)
1161
1292
 
1293
+ const shouldWrapTheme = shouldFlatten && themeVal
1294
+
1162
1295
  if (disableExtractVariables) {
1163
1296
  themeAccessListeners.add((key) => {
1164
1297
  shouldFlatten = false
@@ -1170,13 +1303,15 @@ export function createExtractor() {
1170
1303
 
1171
1304
  if (shouldPrintDebug) {
1172
1305
  // prettier-ignore
1173
- console.log(' - flatten?', objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapThme, allOtherPropsExtractable, hasOnlyStringChildren }))
1306
+ console.log(' - flatten?', objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), 'inlined', [...inlined])
1174
1307
  }
1175
1308
 
1176
1309
  // wrap theme around children on flatten
1177
- if (shouldFlatten && shouldWrapThme) {
1310
+ // TODO move this to bottom and re-check shouldFlatten
1311
+ // account for shouldFlatten could change w the above block "if (disableExtractVariables)"
1312
+ if (shouldFlatten && shouldWrapTheme) {
1178
1313
  if (shouldPrintDebug) {
1179
- console.log(' - wrapping theme', allOtherPropsExtractable, themeVal)
1314
+ console.log(' - wrapping theme', themeVal)
1180
1315
  }
1181
1316
 
1182
1317
  // remove theme attribute from flattened node
@@ -1211,7 +1346,7 @@ export function createExtractor() {
1211
1346
  // only if we flatten, ensure the default styles are there
1212
1347
  if (shouldFlatten && staticConfig.defaultProps) {
1213
1348
  const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
1214
- if (!isValidStyleKey(key)) {
1349
+ if (!isValidStyleKey(key, staticConfig)) {
1215
1350
  return []
1216
1351
  }
1217
1352
  const value = staticConfig.defaultProps[key]
@@ -1273,17 +1408,120 @@ export function createExtractor() {
1273
1408
  console.log(' - ensureOverriden:', Object.keys(ensureOverridden).join(', '))
1274
1409
  }
1275
1410
 
1411
+ const state = {
1412
+ noClassNames: false,
1413
+ focus: false,
1414
+ hover: false,
1415
+ mounted: true, // TODO match logic in createComponent
1416
+ press: false,
1417
+ pressIn: false,
1418
+ }
1419
+
1420
+ // evaluates all static attributes into a simple object
1421
+ let foundStaticProps = {}
1422
+ for (const key in attrs) {
1423
+ const cur = attrs[key]
1424
+ if (cur.type === 'style') {
1425
+ normalizeStyleObject(cur.value)
1426
+ foundStaticProps = {
1427
+ ...foundStaticProps,
1428
+ ...expandStyles(cur.value),
1429
+ }
1430
+ continue
1431
+ }
1432
+ if (cur.type === 'attr') {
1433
+ if (t.isJSXSpreadAttribute(cur.value)) {
1434
+ continue
1435
+ }
1436
+ if (!t.isJSXIdentifier(cur.value.name)) {
1437
+ continue
1438
+ }
1439
+ const key = cur.value.name.name
1440
+ // undefined = boolean true
1441
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true))
1442
+ if (value !== FAILED_EVAL) {
1443
+ foundStaticProps = {
1444
+ ...foundStaticProps,
1445
+ [key]: value,
1446
+ }
1447
+ }
1448
+ }
1449
+ }
1450
+
1451
+ // must preserve exact order
1452
+ const completeProps = {}
1453
+ for (const key in staticConfig.defaultProps) {
1454
+ if (!(key in foundStaticProps)) {
1455
+ completeProps[key] = staticConfig.defaultProps[key]
1456
+ }
1457
+ }
1458
+ for (const key in foundStaticProps) {
1459
+ completeProps[key] = foundStaticProps[key]
1460
+ }
1461
+
1276
1462
  // expand shorthands, de-opt variables
1277
1463
  attrs = attrs.reduce<ExtractedAttr[]>((acc, cur) => {
1278
1464
  if (!cur) return acc
1279
1465
  if (cur.type === 'attr' && !t.isJSXSpreadAttribute(cur.value)) {
1280
1466
  if (shouldFlatten) {
1281
- if (cur.value.name.name === 'tag') {
1282
- // remove tag=""
1283
- return acc
1467
+ const name = cur.value.name.name
1468
+ if (typeof name === 'string') {
1469
+ if (name === 'tag') {
1470
+ // remove tag=""
1471
+ return acc
1472
+ }
1473
+
1474
+ // if flattening, expand variants
1475
+ if (variants[name] && variantValues.has(name)) {
1476
+ let out = Object.fromEntries(
1477
+ staticConfig.propMapper(
1478
+ name,
1479
+ variantValues.get(name),
1480
+ defaultTheme,
1481
+ completeProps,
1482
+ { ...state, resolveVariablesAs: 'auto' },
1483
+ undefined,
1484
+ shouldPrintDebug
1485
+ ) || []
1486
+ )
1487
+ if (out && isTargetingHTML) {
1488
+ const cn = out.className
1489
+ // translate to DOM-compat
1490
+ out = rnw.createDOMProps(isTextView ? 'span' : 'div', out)
1491
+ // remove rnw className use ours
1492
+ out.className = cn
1493
+ }
1494
+ if (shouldPrintDebug) {
1495
+ console.log(' - expanded variant', name, out)
1496
+ }
1497
+ for (const key in out) {
1498
+ const value = out[key]
1499
+ if (isValidStyleKey(key, staticConfig)) {
1500
+ acc.push({
1501
+ type: 'style',
1502
+ value: { [key]: value },
1503
+ name: key,
1504
+ attr: cur.value,
1505
+ } as const)
1506
+ } else {
1507
+ acc.push({
1508
+ type: 'attr',
1509
+ value: t.jsxAttribute(
1510
+ t.jsxIdentifier(key),
1511
+ t.jsxExpressionContainer(
1512
+ typeof value === 'string'
1513
+ ? t.stringLiteral(value)
1514
+ : literalToAst(value)
1515
+ )
1516
+ ),
1517
+ })
1518
+ }
1519
+ }
1520
+ }
1284
1521
  }
1285
1522
  }
1286
1523
  }
1524
+
1287
1525
  if (cur.type !== 'style') {
1288
1526
  acc.push(cur)
1289
1527
  return acc
@@ -1403,57 +1641,6 @@ export function createExtractor() {
1403
1641
  return acc
1404
1642
  }, [])
1405
1643
 
1406
- const state = {
1407
- noClassNames: true,
1408
- focus: false,
1409
- hover: false,
1410
- mounted: true, // TODO match logic in createComponent
1411
- press: false,
1412
- pressIn: false,
1413
- }
1414
-
1415
- // evaluates all static attributes into a simple object
1416
- let foundStaticProps = {}
1417
- for (const key in attrs) {
1418
- const cur = attrs[key]
1419
- if (cur.type === 'style') {
1420
- normalizeStyleObject(cur.value)
1421
- foundStaticProps = {
1422
- ...foundStaticProps,
1423
- ...expandStyles(cur.value),
1424
- }
1425
- continue
1426
- }
1427
- if (cur.type === 'attr') {
1428
- if (t.isJSXSpreadAttribute(cur.value)) {
1429
- continue
1430
- }
1431
- if (!t.isJSXIdentifier(cur.value.name)) {
1432
- continue
1433
- }
1434
- const key = cur.value.name.name
1435
- // undefined = boolean true
1436
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true))
1437
- if (value !== FAILED_EVAL) {
1438
- foundStaticProps = {
1439
- ...foundStaticProps,
1440
- [key]: value,
1441
- }
1442
- }
1443
- }
1444
- }
1445
-
1446
- // must preserve exact order
1447
- const completeProps = {}
1448
- for (const key in staticConfig.defaultProps) {
1449
- if (!(key in foundStaticProps)) {
1450
- completeProps[key] = staticConfig.defaultProps[key]
1451
- }
1452
- }
1453
- for (const key in foundStaticProps) {
1454
- completeProps[key] = foundStaticProps[key]
1455
- }
1456
-
1457
1644
  if (shouldPrintDebug) {
1458
1645
  console.log(' - attrs (combined 🔀): \n', logLines(attrs.map(attrStr).join(', ')))
1459
1646
  console.log(' - defaultProps: \n', logLines(objToStr(staticConfig.defaultProps)))
@@ -1488,19 +1675,22 @@ export function createExtractor() {
1488
1675
  undefined,
1489
1676
  props['debug']
1490
1677
  )
1678
+
1679
+ // console.log('outout', out)
1680
+
1491
1681
  const outStyle = {
1492
1682
  ...out.style,
1493
1683
  ...out.pseudos,
1494
1684
  }
1495
- omitInvalidStyles(outStyle)
1496
- if (shouldPrintDebug) {
1497
- // prettier-ignore
1498
- console.log(` getStyles ${debugName} (props):\n`, logLines(objToStr(props)))
1499
- // prettier-ignore
1500
- console.log(` getStyles ${debugName} (out.viewProps):\n`, logLines(objToStr(out.viewProps)))
1501
- // prettier-ignore
1502
- console.log(` getStyles ${debugName} (out.style):\n`, logLines(objToStr(outStyle || {}), true))
1503
- }
1685
+ // omitInvalidStyles(outStyle)
1686
+ // if (shouldPrintDebug) {
1687
+ // // prettier-ignore
1688
+ // console.log(` getStyles ${debugName} (props):\n`, logLines(objToStr(props)))
1689
+ // // prettier-ignore
1690
+ // console.log(` getStyles ${debugName} (out.viewProps):\n`, logLines(objToStr(out.viewProps)))
1691
+ // // prettier-ignore
1692
+ // console.log(` getStyles ${debugName} (out.style):\n`, logLines(objToStr(outStyle || {}), true))
1693
+ // }
1504
1694
  return outStyle
1505
1695
  } catch (err: any) {
1506
1696
  console.log('error', err.message, err.stack)
@@ -1553,9 +1743,9 @@ export function createExtractor() {
1553
1743
 
1554
1744
  if (shouldPrintDebug) {
1555
1745
  // prettier-ignore
1556
- console.log(' -- addInitialStyleKeys', addInitialStyleKeys.join(', '), { shouldFlatten })
1746
+ if (shouldFlatten) console.log(' -- addInitialStyleKeys', addInitialStyleKeys.join(', '))
1557
1747
  // prettier-ignore
1558
- console.log(' -- completeStyles:\n', logLines(objToStr(completeStyles)))
1748
+ // console.log(' -- completeStyles:\n', logLines(objToStr(completeStyles)))
1559
1749
  }
1560
1750
 
1561
1751
  let getStyleError: any = null
@@ -1572,19 +1762,15 @@ export function createExtractor() {
1572
1762
  if (shouldPrintDebug) console.log(' => tern ', attrStr(attr))
1573
1763
  continue
1574
1764
  case 'style':
1575
- if (shouldPrintDebug) console.log(' * styles in', attr.value)
1576
1765
  // expand variants and such
1577
- // get the keys we need
1578
1766
  const styles = getStyles(attr.value, 'style')
1579
- // prettier-ignore
1580
- if (shouldPrintDebug) console.log(' * styles out', logLines(objToStr(styles)))
1581
1767
  if (styles) {
1582
- // but actually resolve them to the full object
1583
- // TODO media/pseudo merging
1584
- attr.value = Object.fromEntries(
1585
- Object.keys(styles).map((k) => [k, completeStyles[k]])
1586
- )
1768
+ attr.value = styles
1587
1769
  }
1770
+ // prettier-ignore
1771
+ if (shouldPrintDebug) console.log(' * styles (in)', logLines(objToStr(attr.value)))
1772
+ // prettier-ignore
1773
+ if (shouldPrintDebug) console.log(' * styles (out)', logLines(objToStr(styles)))
1588
1774
  continue
1589
1775
  }
1590
1776
  } catch (err) {
@@ -1612,7 +1798,7 @@ export function createExtractor() {
1612
1798
  const attr = attrs[i]
1613
1799
 
1614
1800
  // if flattening map inline props to proper flattened names
1615
- if (shouldFlatten && canFlattenProps) {
1801
+ if (shouldFlatten) {
1616
1802
  if (attr.type === 'attr') {
1617
1803
  if (t.isJSXAttribute(attr.value)) {
1618
1804
  if (t.isJSXIdentifier(attr.value.name)) {
@@ -1621,6 +1807,15 @@ export function createExtractor() {
1621
1807
  // map to HTML only name
1622
1808
  attr.value.name.name = INLINE_EXTRACTABLE[name]
1623
1809
  }
1810
+
1811
+ // if flattening expand turn variants into styles
1812
+ if (staticConfig.variants?.[name]) {
1813
+ const expanded = getStyles({})
1814
+ // attrs[i] = {
1815
+ // type: 'style',
1816
+ // value:
1817
+ // }
1818
+ }
1624
1819
  }
1625
1820
  }
1626
1821
  }