@tamagui/static 1.132.15 → 1.132.16-1754855349219

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 (67) hide show
  1. package/dist/extractor/createExtractor.js +44 -107
  2. package/dist/extractor/createExtractor.js.map +1 -1
  3. package/dist/extractor/createExtractor.native.js +52 -112
  4. package/dist/extractor/createExtractor.native.js.map +2 -2
  5. package/dist/extractor/extractMediaStyle.js +1 -1
  6. package/dist/extractor/extractMediaStyle.js.map +1 -1
  7. package/dist/extractor/extractMediaStyle.native.js +1 -1
  8. package/dist/extractor/extractMediaStyle.native.js.map +2 -2
  9. package/dist/extractor/extractToClassNames.js +199 -168
  10. package/dist/extractor/extractToClassNames.js.map +2 -2
  11. package/dist/extractor/extractToClassNames.native.js +191 -185
  12. package/dist/extractor/extractToClassNames.native.js.map +2 -2
  13. package/dist/extractor/extractToNative.js +47 -78
  14. package/dist/extractor/extractToNative.js.map +1 -1
  15. package/dist/extractor/extractToNative.native.js +23 -39
  16. package/dist/extractor/extractToNative.native.js.map +2 -2
  17. package/dist/extractor/normalizeTernaries.js +5 -3
  18. package/dist/extractor/normalizeTernaries.js.map +1 -1
  19. package/dist/extractor/normalizeTernaries.native.js +5 -3
  20. package/dist/extractor/normalizeTernaries.native.js.map +2 -2
  21. package/dist/extractor/propsToFontFamilyCache.js +7 -8
  22. package/dist/extractor/propsToFontFamilyCache.js.map +1 -1
  23. package/dist/extractor/propsToFontFamilyCache.native.js +9 -10
  24. package/dist/extractor/propsToFontFamilyCache.native.js.map +2 -2
  25. package/dist/registerRequire.js +1 -1
  26. package/dist/registerRequire.js.map +1 -1
  27. package/dist/registerRequire.native.js +1 -1
  28. package/dist/registerRequire.native.js.map +1 -1
  29. package/dist/types.native.js.map +1 -1
  30. package/package.json +15 -15
  31. package/src/extractor/createExtractor.ts +74 -172
  32. package/src/extractor/extractMediaStyle.ts +1 -1
  33. package/src/extractor/extractToClassNames.ts +358 -261
  34. package/src/extractor/extractToNative.ts +68 -111
  35. package/src/extractor/normalizeTernaries.ts +10 -3
  36. package/src/extractor/propsToFontFamilyCache.ts +5 -5
  37. package/src/registerRequire.ts +1 -1
  38. package/src/types.ts +9 -13
  39. package/types/extractor/createExtractor.d.ts.map +1 -1
  40. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  41. package/types/extractor/extractToNative.d.ts.map +1 -1
  42. package/types/extractor/normalizeTernaries.d.ts.map +1 -1
  43. package/types/extractor/propsToFontFamilyCache.d.ts +2 -2
  44. package/types/extractor/propsToFontFamilyCache.d.ts.map +1 -1
  45. package/types/types.d.ts +8 -10
  46. package/types/types.d.ts.map +1 -1
  47. package/dist/extractor/buildClassName.js +0 -72
  48. package/dist/extractor/buildClassName.js.map +0 -6
  49. package/dist/extractor/buildClassName.native.js +0 -67
  50. package/dist/extractor/buildClassName.native.js.map +0 -6
  51. package/dist/extractor/ensureImportingConcat.js +0 -50
  52. package/dist/extractor/ensureImportingConcat.js.map +0 -6
  53. package/dist/extractor/ensureImportingConcat.native.js +0 -49
  54. package/dist/extractor/ensureImportingConcat.native.js.map +0 -6
  55. package/dist/extractor/hoistClassNames.js +0 -63
  56. package/dist/extractor/hoistClassNames.js.map +0 -6
  57. package/dist/extractor/hoistClassNames.native.js +0 -66
  58. package/dist/extractor/hoistClassNames.native.js.map +0 -6
  59. package/src/extractor/buildClassName.ts +0 -76
  60. package/src/extractor/ensureImportingConcat.ts +0 -36
  61. package/src/extractor/hoistClassNames.ts +0 -52
  62. package/types/extractor/buildClassName.d.ts +0 -7
  63. package/types/extractor/buildClassName.d.ts.map +0 -1
  64. package/types/extractor/ensureImportingConcat.d.ts +0 -4
  65. package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
  66. package/types/extractor/hoistClassNames.d.ts +0 -6
  67. package/types/extractor/hoistClassNames.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/types.ts"],
4
- "mappings": ";;;;;;;;;;;;AA4FE;;",
4
+ "mappings": ";;;;;;;;;;;;AAwFE;;",
5
5
  "names": []
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.132.15",
3
+ "version": "1.132.16-1754855349219",
4
4
  "source": "src/index.ts",
5
5
  "types": "./types/index.d.ts",
6
6
  "type": "commonjs",
@@ -45,19 +45,19 @@
45
45
  "@babel/template": "^7.25.0",
46
46
  "@babel/traverse": "^7.25.4",
47
47
  "@babel/types": "^7.25.4",
48
- "@tamagui/cli-color": "1.132.15",
49
- "@tamagui/config-default": "1.132.15",
50
- "@tamagui/core": "1.132.15",
51
- "@tamagui/fake-react-native": "1.132.15",
52
- "@tamagui/generate-themes": "1.132.15",
53
- "@tamagui/helpers": "1.132.15",
54
- "@tamagui/helpers-node": "1.132.15",
55
- "@tamagui/proxy-worm": "1.132.15",
56
- "@tamagui/react-native-web-internals": "1.132.15",
57
- "@tamagui/react-native-web-lite": "1.132.15",
58
- "@tamagui/shorthands": "1.132.15",
59
- "@tamagui/types": "1.132.15",
60
- "@tamagui/web": "1.132.15",
48
+ "@tamagui/cli-color": "1.132.16-1754855349219",
49
+ "@tamagui/config-default": "1.132.16-1754855349219",
50
+ "@tamagui/core": "1.132.16-1754855349219",
51
+ "@tamagui/fake-react-native": "1.132.16-1754855349219",
52
+ "@tamagui/generate-themes": "1.132.16-1754855349219",
53
+ "@tamagui/helpers": "1.132.16-1754855349219",
54
+ "@tamagui/helpers-node": "1.132.16-1754855349219",
55
+ "@tamagui/proxy-worm": "1.132.16-1754855349219",
56
+ "@tamagui/react-native-web-internals": "1.132.16-1754855349219",
57
+ "@tamagui/react-native-web-lite": "1.132.16-1754855349219",
58
+ "@tamagui/shorthands": "1.132.16-1754855349219",
59
+ "@tamagui/types": "1.132.16-1754855349219",
60
+ "@tamagui/web": "1.132.16-1754855349219",
61
61
  "babel-literal-to-ast": "^2.1.0",
62
62
  "browserslist": "^4.22.2",
63
63
  "check-dependency-version-consistency": "^4.1.0",
@@ -74,7 +74,7 @@
74
74
  "devDependencies": {
75
75
  "@babel/plugin-syntax-typescript": "^7.25.4",
76
76
  "@expo/match-media": "^0.4.0",
77
- "@tamagui/build": "1.132.15",
77
+ "@tamagui/build": "1.132.16-1754855349219",
78
78
  "@types/babel__core": "^7.20.5",
79
79
  "@types/find-root": "^1.1.2",
80
80
  "@types/node": "^22.1.0",
@@ -46,7 +46,6 @@ import { loadTamagui, loadTamaguiSync } from './loadTamagui'
46
46
  import { logLines } from './logLines'
47
47
  import { normalizeTernaries } from './normalizeTernaries'
48
48
  import { setPropsToFontFamily } from './propsToFontFamilyCache'
49
- import { removeUnusedHooks } from './removeUnusedHooks'
50
49
  import { timer } from './timer'
51
50
  import { validHTMLAttributes } from './validHTMLAttributes'
52
51
 
@@ -164,11 +163,10 @@ export function createExtractor(
164
163
  evaluateVars = true,
165
164
  sourcePath = '',
166
165
  onExtractTag,
167
- onStyleRule,
166
+ onStyledDefinitionRule,
168
167
  getFlattenedNode,
169
168
  disable,
170
169
  disableExtraction,
171
- disableExtractInlineMedia,
172
170
  disableExtractVariables,
173
171
  disableDebugAttr,
174
172
  enableDynamicEvaluation = false,
@@ -676,7 +674,7 @@ export function createExtractor(
676
674
  if (out.rulesToInsert) {
677
675
  for (const key in out.rulesToInsert) {
678
676
  const styleObject = out.rulesToInsert[key]
679
- onStyleRule?.(
677
+ onStyledDefinitionRule?.(
680
678
  styleObject[StyleObjectIdentifier],
681
679
  styleObject[StyleObjectRules]
682
680
  )
@@ -1018,12 +1016,9 @@ export function createExtractor(
1018
1016
  }
1019
1017
  // split into individual ternaries per object property
1020
1018
  return [
1021
- ...(createTernariesFromObjectProperties(test, alt) || []),
1019
+ ...(flattenNestedTernaries(test, alt) || []),
1022
1020
  ...((cons &&
1023
- createTernariesFromObjectProperties(
1024
- t.unaryExpression('!', test),
1025
- cons
1026
- )) ||
1021
+ flattenNestedTernaries(t.unaryExpression('!', test), cons)) ||
1027
1022
  []),
1028
1023
  ].map((ternary) => ({
1029
1024
  type: 'ternary',
@@ -1099,18 +1094,9 @@ export function createExtractor(
1099
1094
  if (name[0] === '$' && t.isJSXExpressionContainer(attribute?.value)) {
1100
1095
  const shortname = name.slice(1)
1101
1096
  if (mediaQueryConfig[shortname]) {
1102
- if (platform === 'native') {
1103
- shouldDeopt = true
1104
- }
1105
-
1106
- // allow disabling this extraction
1107
- if (disableExtractInlineMedia) {
1108
- return attr
1109
- }
1110
-
1111
1097
  const expression = attribute.value.expression
1112
1098
  if (!t.isJSXEmptyExpression(expression)) {
1113
- const ternaries = createTernariesFromObjectProperties(
1099
+ const ternaries = flattenNestedTernaries(
1114
1100
  t.stringLiteral(shortname),
1115
1101
  expression,
1116
1102
  {
@@ -1332,17 +1318,6 @@ export function createExtractor(
1332
1318
  return { type: 'ternary', value: staticLogical }
1333
1319
  }
1334
1320
 
1335
- // Disabling: this probably doesn't optimize much and needs to be done a bit differently
1336
- if (options.experimentalFlattenDynamicValues) {
1337
- if (isValidStyleKey(name, staticConfig)) {
1338
- return {
1339
- type: 'dynamic-style',
1340
- value,
1341
- name: tamaguiConfig?.shorthands[name] || name,
1342
- }
1343
- }
1344
- }
1345
-
1346
1321
  // if we've made it this far, the prop stays inline
1347
1322
  inlined.set(name, true)
1348
1323
  if (shouldPrintDebug) {
@@ -1461,7 +1436,7 @@ export function createExtractor(
1461
1436
  // => Ternary<test && x, { background: 'red' }, null>
1462
1437
  // => Ternary<test && !x, { background: 'green' }, null>
1463
1438
  // => Ternary<test && '$gtSm', { color: 'green' }, null>
1464
- function createTernariesFromObjectProperties(
1439
+ function flattenNestedTernaries(
1465
1440
  test: t.Expression,
1466
1441
  side: t.Expression | null,
1467
1442
  ternaryPartial: Partial<Ternary> = {}
@@ -1476,34 +1451,6 @@ export function createExtractor(
1476
1451
  if (!t.isObjectProperty(property)) {
1477
1452
  throw new Error('expected object property')
1478
1453
  }
1479
- // handle media queries inside spread/conditional objects
1480
- if (t.isIdentifier(property.key)) {
1481
- const key = property.key.name
1482
- const mediaQueryKey = key.slice(1)
1483
- const isMediaQuery = key[0] === '$' && mediaQueryConfig[mediaQueryKey]
1484
- if (isMediaQuery) {
1485
- if (t.isExpression(property.value)) {
1486
- const ternaries = createTernariesFromObjectProperties(
1487
- t.stringLiteral(mediaQueryKey),
1488
- property.value,
1489
- {
1490
- inlineMediaQuery: mediaQueryKey,
1491
- }
1492
- )
1493
- if (ternaries) {
1494
- return ternaries.map((value) => ({
1495
- ...ternaryPartial,
1496
- ...value,
1497
- // ensure media query test stays on left side (see getMediaQueryTernary)
1498
- test: t.logicalExpression('&&', value.test, test),
1499
- }))
1500
- }
1501
- logger.info(['⚠️ no ternaries?', property].join(' '))
1502
- } else {
1503
- logger.info(['⚠️ not expression', property].join(' '))
1504
- }
1505
- }
1506
- }
1507
1454
  // this could be a recurse here if we want to get fancy
1508
1455
  if (t.isConditionalExpression(property.value)) {
1509
1456
  // merge up into the parent conditional, split into two
@@ -1619,66 +1566,70 @@ export function createExtractor(
1619
1566
  }
1620
1567
  })
1621
1568
 
1622
- // only if we flatten, ensure the default styles are there
1623
- if (shouldFlatten) {
1624
- let skipMap = false
1625
- const defaultStyleAttrs = Object.keys(defaultProps).flatMap((key) => {
1626
- if (skipMap) return []
1627
- const value = defaultProps[key]
1628
- if (key === 'theme' && !themeVal) {
1629
- if (platform === 'native') {
1630
- shouldFlatten = false
1631
- skipMap = true
1632
- inlined.set('theme', { value: t.stringLiteral(value) })
1633
- }
1634
- themeVal = { value: t.stringLiteral(value) }
1635
- return []
1636
- }
1637
- if (!isValidStyleKey(key, staticConfig)) {
1638
- return []
1639
- }
1640
- const name = tamaguiConfig?.shorthands[key] || key
1641
- if (value === undefined) {
1642
- logger.warn(
1643
- `⚠️ Error evaluating default style for component, prop ${key} ${value}`
1644
- )
1645
- shouldDeopt = true
1646
- return
1647
- }
1648
- if (name[0] === '$' && mediaQueryConfig[name.slice(1)]) {
1649
- defaultProps[key] = undefined
1650
- return evaluateAttribute({
1651
- node: t.jsxAttribute(
1652
- t.jsxIdentifier(name),
1653
- t.jsxExpressionContainer(
1654
- t.objectExpression(
1655
- Object.keys(value)
1656
- .filter((k) => {
1657
- return typeof value[k] !== 'undefined'
1658
- })
1659
- .map((k) => {
1660
- return t.objectProperty(
1661
- t.identifier(k),
1662
- literalToAst(value[k])
1663
- )
1664
- })
1665
- )
1569
+ if (!shouldFlatten) {
1570
+ // were no longer partially optimizing, it adds a lot of complexity for dubious performance
1571
+ if (shouldPrintDebug) {
1572
+ logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`)
1573
+ }
1574
+ node.attributes = ogAttributes
1575
+ return
1576
+ }
1577
+
1578
+ // ensure the default styles are there
1579
+ let skipMap = false
1580
+ const defaultStyleAttrs = Object.keys(defaultProps).flatMap((key) => {
1581
+ if (skipMap) return []
1582
+ const value = defaultProps[key]
1583
+ if (key === 'theme' && !themeVal) {
1584
+ if (platform === 'native') {
1585
+ shouldFlatten = false
1586
+ skipMap = true
1587
+ inlined.set('theme', { value: t.stringLiteral(value) })
1588
+ }
1589
+ themeVal = { value: t.stringLiteral(value) }
1590
+ return []
1591
+ }
1592
+ if (!isValidStyleKey(key, staticConfig)) {
1593
+ return []
1594
+ }
1595
+ const name = tamaguiConfig?.shorthands[key] || key
1596
+ if (value === undefined) {
1597
+ logger.warn(
1598
+ `⚠️ Error evaluating default style for component, prop ${key} ${value}`
1599
+ )
1600
+ shouldDeopt = true
1601
+ return
1602
+ }
1603
+ if (name[0] === '$' && mediaQueryConfig[name.slice(1)]) {
1604
+ defaultProps[key] = undefined
1605
+ return evaluateAttribute({
1606
+ node: t.jsxAttribute(
1607
+ t.jsxIdentifier(name),
1608
+ t.jsxExpressionContainer(
1609
+ t.objectExpression(
1610
+ Object.keys(value)
1611
+ .filter((k) => {
1612
+ return typeof value[k] !== 'undefined'
1613
+ })
1614
+ .map((k) => {
1615
+ return t.objectProperty(t.identifier(k), literalToAst(value[k]))
1616
+ })
1666
1617
  )
1667
- ),
1668
- } as any)
1669
- }
1670
- const attr: ExtractedAttrStyle = {
1671
- type: 'style',
1672
- name,
1673
- value: { [name]: value },
1674
- }
1675
- return attr
1676
- }) as ExtractedAttr[]
1618
+ )
1619
+ ),
1620
+ } as any)
1621
+ }
1622
+ const attr: ExtractedAttrStyle = {
1623
+ type: 'style',
1624
+ name,
1625
+ value: { [name]: value },
1626
+ }
1627
+ return attr
1628
+ }) as ExtractedAttr[]
1677
1629
 
1678
- if (!skipMap) {
1679
- if (defaultStyleAttrs.length) {
1680
- attrs = [...defaultStyleAttrs, ...attrs]
1681
- }
1630
+ if (!skipMap) {
1631
+ if (defaultStyleAttrs.length) {
1632
+ attrs = [...defaultStyleAttrs, ...attrs]
1682
1633
  }
1683
1634
  }
1684
1635
 
@@ -1723,10 +1674,9 @@ export function createExtractor(
1723
1674
  }, [])
1724
1675
  .flat()
1725
1676
 
1726
- const shouldWrapTheme = shouldFlatten && themeVal
1727
1677
  // wrap theme around children on flatten
1728
1678
  // account for shouldFlatten could change w the above block "if (disableExtractVariables)"
1729
- if (shouldWrapTheme) {
1679
+ if (themeVal) {
1730
1680
  if (!programPath) {
1731
1681
  console.warn(
1732
1682
  `No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
@@ -1774,38 +1724,6 @@ export function createExtractor(
1774
1724
  }
1775
1725
  }
1776
1726
 
1777
- if (shouldPrintDebug) {
1778
- try {
1779
- // prettier-ignore
1780
- logger.info(
1781
- [
1782
- ' flatten?',
1783
- shouldFlatten,
1784
- objToStr({
1785
- hasSpread,
1786
- shouldDeopt,
1787
- canFlattenProps,
1788
- shouldWrapTheme,
1789
- hasOnlyStringChildren,
1790
- }),
1791
- 'inlined',
1792
- inlined.size,
1793
- [...inlined],
1794
- ].join(' ')
1795
- )
1796
- } catch {
1797
- // ok
1798
- }
1799
- }
1800
-
1801
- if (shouldDeopt || !shouldFlatten) {
1802
- if (shouldPrintDebug) {
1803
- logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`)
1804
- }
1805
- node.attributes = ogAttributes
1806
- return
1807
- }
1808
-
1809
1727
  if (shouldPrintDebug) {
1810
1728
  logger.info(
1811
1729
  [' - attrs (flattened): \n', logLines(attrs.map(attrStr).join(', '))].join(
@@ -2101,12 +2019,10 @@ export function createExtractor(
2101
2019
  }
2102
2020
 
2103
2021
  // add default props
2104
- if (shouldFlatten) {
2105
- attrs.unshift({
2106
- type: 'style',
2107
- value: defaultProps,
2108
- })
2109
- }
2022
+ attrs.unshift({
2023
+ type: 'style',
2024
+ value: defaultProps,
2025
+ })
2110
2026
 
2111
2027
  attrs = attrs.reduce<ExtractedAttr[]>((acc, cur) => {
2112
2028
  if (cur.type === 'style') {
@@ -2296,15 +2212,6 @@ export function createExtractor(
2296
2212
  }
2297
2213
  }
2298
2214
  }
2299
-
2300
- if (attr.type === 'dynamic-style') {
2301
- if (existingStyleKeys.has(attr.name)) {
2302
- //@ts-ignore
2303
- attrs[i] = undefined
2304
- } else {
2305
- existingStyleKeys.add(attr.name)
2306
- }
2307
- }
2308
2215
  }
2309
2216
 
2310
2217
  if (options.experimentalFlattenThemesOnNative) {
@@ -2337,10 +2244,7 @@ export function createExtractor(
2337
2244
 
2338
2245
  // delete empty styles:
2339
2246
  attrs = attrs.filter((x) => {
2340
- if (
2341
- (x.type === 'style' || x.type === 'dynamic-style') &&
2342
- Object.keys(x.value).length === 0
2343
- ) {
2247
+ if (x.type === 'style' && Object.keys(x.value).length === 0) {
2344
2248
  return false
2345
2249
  }
2346
2250
  return true
@@ -2394,7 +2298,6 @@ export function createExtractor(
2394
2298
  staticConfig.neverFlatten ? 'neverFlatten' : '',
2395
2299
  ].join(' ')
2396
2300
  )
2397
- logger.info(` - shouldFlatten/isFlattened: ${shouldFlatten}`)
2398
2301
  logger.info(` - attrs (end):\n ${logLines(attrs.map(attrStr).join(', '))}`)
2399
2302
  }
2400
2303
 
@@ -2408,7 +2311,6 @@ export function createExtractor(
2408
2311
  attemptEval,
2409
2312
  jsxPath: traversePath,
2410
2313
  originalNodeName,
2411
- isFlattened: shouldFlatten,
2412
2314
  programPath: programPath!,
2413
2315
  completeProps,
2414
2316
  staticConfig,
@@ -17,7 +17,7 @@ export function extractMediaStyle(
17
17
  importance = 0,
18
18
  shouldPrintDebug: boolean | 'verbose' = false
19
19
  ) {
20
- const { getCSSStylesAtomic, mediaObjectToString } = requireTamaguiCore('web')
20
+ const { getCSSStylesAtomic } = requireTamaguiCore('web')
21
21
  const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
22
22
  if (!mt) {
23
23
  return null