@tamagui/static 2.7.7 → 3.0.0-beta.643.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 (329) hide show
  1. package/dist/cjs/check-dep-versions.cjs +355 -0
  2. package/dist/cjs/checkDeps.cjs +302 -0
  3. package/dist/cjs/compiler.cjs +286 -0
  4. package/dist/cjs/compilerHost.cjs +1695 -0
  5. package/dist/cjs/constants.cjs +33 -0
  6. package/dist/cjs/domStructuralPass.cjs +112 -0
  7. package/dist/cjs/exports.cjs +42 -0
  8. package/dist/cjs/extractor/addLocalExports.cjs +64 -0
  9. package/dist/cjs/extractor/bundle.cjs +203 -0
  10. package/dist/cjs/extractor/bundleConfig.cjs +747 -0
  11. package/dist/cjs/extractor/concatClassName.cjs +117 -0
  12. package/dist/cjs/extractor/detectModuleFormat.cjs +54 -0
  13. package/dist/cjs/extractor/esbuildAliasPlugin.cjs +47 -0
  14. package/dist/cjs/extractor/esbuildTsconfigPaths.cjs +92 -0
  15. package/dist/cjs/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +38 -0
  16. package/dist/cjs/extractor/loadTamagui.cjs +344 -0
  17. package/dist/cjs/extractor/regenerateConfig.cjs +161 -0
  18. package/dist/cjs/extractor/watchTamaguiConfig.cjs +64 -0
  19. package/dist/cjs/getPragmaOptions.cjs +67 -0
  20. package/dist/cjs/helpers/memoize.cjs +42 -0
  21. package/dist/cjs/helpers/requireTamaguiCore.cjs +40 -0
  22. package/dist/cjs/index.cjs +34 -0
  23. package/dist/cjs/registerRequire.cjs +220 -0
  24. package/dist/cjs/server.cjs +66 -0
  25. package/dist/cjs/staticEvaluationIgnoredModules.cjs +86 -0
  26. package/dist/cjs/types.cjs +17 -0
  27. package/dist/cjs/zero/artifact.cjs +145 -0
  28. package/dist/cjs/zero/graph.cjs +209 -0
  29. package/dist/cjs/zero/identity.cjs +61 -0
  30. package/dist/cjs/zero/index.cjs +26 -0
  31. package/dist/cjs/zero/islands.cjs +232 -0
  32. package/dist/cjs/zero/options.cjs +163 -0
  33. package/dist/cjs/zero/ownership.cjs +79 -0
  34. package/dist/cjs/zero/theme.cjs +328 -0
  35. package/dist/cjs/zero/transform.cjs +203 -0
  36. package/dist/esm/check-dep-versions.mjs +329 -0
  37. package/dist/esm/check-dep-versions.mjs.map +1 -0
  38. package/dist/esm/checkDeps.mjs +279 -0
  39. package/dist/esm/checkDeps.mjs.map +1 -0
  40. package/dist/esm/compiler.mjs +255 -0
  41. package/dist/esm/compiler.mjs.map +1 -0
  42. package/dist/esm/compilerHost.mjs +1675 -0
  43. package/dist/esm/compilerHost.mjs.map +1 -0
  44. package/dist/esm/constants.mjs +7 -0
  45. package/dist/esm/constants.mjs.map +1 -0
  46. package/dist/esm/domStructuralPass.mjs +92 -0
  47. package/dist/esm/domStructuralPass.mjs.map +1 -0
  48. package/dist/esm/exports.mjs +26 -0
  49. package/dist/esm/extractor/addLocalExports.mjs +44 -0
  50. package/dist/esm/extractor/addLocalExports.mjs.map +1 -0
  51. package/dist/esm/extractor/bundle.mjs +173 -0
  52. package/dist/esm/extractor/bundle.mjs.map +1 -0
  53. package/dist/esm/extractor/bundleConfig.mjs +706 -0
  54. package/dist/esm/extractor/bundleConfig.mjs.map +1 -0
  55. package/dist/esm/extractor/concatClassName.mjs +96 -0
  56. package/dist/esm/extractor/concatClassName.mjs.map +1 -0
  57. package/dist/esm/extractor/detectModuleFormat.mjs +31 -0
  58. package/dist/esm/extractor/detectModuleFormat.mjs.map +1 -0
  59. package/dist/esm/extractor/esbuildAliasPlugin.mjs +26 -0
  60. package/dist/esm/extractor/esbuildAliasPlugin.mjs.map +1 -0
  61. package/dist/esm/extractor/esbuildTsconfigPaths.mjs +63 -0
  62. package/dist/esm/extractor/esbuildTsconfigPaths.mjs.map +1 -0
  63. package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +18 -0
  64. package/dist/esm/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
  65. package/dist/esm/extractor/loadTamagui.mjs +306 -0
  66. package/dist/esm/extractor/loadTamagui.mjs.map +1 -0
  67. package/dist/esm/extractor/regenerateConfig.mjs +131 -0
  68. package/dist/esm/extractor/regenerateConfig.mjs.map +1 -0
  69. package/dist/esm/extractor/watchTamaguiConfig.mjs +43 -0
  70. package/dist/esm/extractor/watchTamaguiConfig.mjs.map +1 -0
  71. package/dist/esm/getPragmaOptions.mjs +46 -0
  72. package/dist/esm/getPragmaOptions.mjs.map +1 -0
  73. package/dist/esm/helpers/memoize.mjs +21 -0
  74. package/dist/esm/helpers/memoize.mjs.map +1 -0
  75. package/dist/esm/helpers/requireTamaguiCore.mjs +19 -0
  76. package/dist/esm/helpers/requireTamaguiCore.mjs.map +1 -0
  77. package/dist/esm/index.mjs +8 -0
  78. package/dist/esm/index.mjs.map +1 -0
  79. package/dist/esm/registerRequire.mjs +195 -0
  80. package/dist/esm/registerRequire.mjs.map +1 -0
  81. package/dist/esm/server.mjs +40 -0
  82. package/dist/esm/server.mjs.map +1 -0
  83. package/dist/esm/setup.mjs +0 -0
  84. package/dist/esm/staticEvaluationIgnoredModules.mjs +61 -0
  85. package/dist/esm/staticEvaluationIgnoredModules.mjs.map +1 -0
  86. package/dist/esm/types.mjs +0 -0
  87. package/dist/esm/zero/artifact.mjs +119 -0
  88. package/dist/esm/zero/artifact.mjs.map +1 -0
  89. package/dist/esm/zero/graph.mjs +170 -0
  90. package/dist/esm/zero/graph.mjs.map +1 -0
  91. package/dist/esm/zero/identity.mjs +36 -0
  92. package/dist/esm/zero/identity.mjs.map +1 -0
  93. package/dist/esm/zero/index.mjs +15 -0
  94. package/dist/esm/zero/islands.mjs +197 -0
  95. package/dist/esm/zero/islands.mjs.map +1 -0
  96. package/dist/esm/zero/options.mjs +129 -0
  97. package/dist/esm/zero/options.mjs.map +1 -0
  98. package/dist/esm/zero/ownership.mjs +48 -0
  99. package/dist/esm/zero/ownership.mjs.map +1 -0
  100. package/dist/esm/zero/theme.mjs +303 -0
  101. package/dist/esm/zero/theme.mjs.map +1 -0
  102. package/dist/esm/zero/transform.mjs +177 -0
  103. package/dist/esm/zero/transform.mjs.map +1 -0
  104. package/package.json +33 -43
  105. package/src/check-dep-versions.ts +2 -2
  106. package/src/checkDeps.ts +3 -2
  107. package/src/compiler.ts +425 -0
  108. package/src/compilerHost.ts +3125 -0
  109. package/src/constants.ts +0 -5
  110. package/src/domStructuralPass.ts +170 -0
  111. package/src/exports.ts +3 -6
  112. package/src/extractor/addLocalExports.ts +49 -0
  113. package/src/extractor/bundle.ts +20 -35
  114. package/src/extractor/bundleConfig.ts +334 -187
  115. package/src/extractor/concatClassName.ts +13 -20
  116. package/src/extractor/getTamaguiConfigPathFromOptionsConfig.ts +5 -4
  117. package/src/extractor/loadTamagui.ts +196 -143
  118. package/src/extractor/regenerateConfig.ts +65 -13
  119. package/src/extractor/watchTamaguiConfig.ts +6 -1
  120. package/src/helpers/requireTamaguiCore.ts +6 -1
  121. package/src/registerRequire.ts +94 -132
  122. package/src/staticEvaluationIgnoredModules.ts +74 -0
  123. package/src/types.ts +2 -107
  124. package/src/zero/artifact.ts +142 -0
  125. package/src/zero/graph.ts +359 -0
  126. package/src/zero/identity.ts +73 -0
  127. package/src/zero/index.ts +8 -0
  128. package/src/zero/islands.ts +262 -0
  129. package/src/zero/options.ts +239 -0
  130. package/src/zero/ownership.ts +113 -0
  131. package/src/zero/theme.ts +478 -0
  132. package/src/zero/transform.ts +320 -0
  133. package/types/check-dep-versions.d.ts.map +1 -1
  134. package/types/checkDeps.d.ts.map +1 -1
  135. package/types/compiler.d.ts +117 -0
  136. package/types/compiler.d.ts.map +1 -0
  137. package/types/compilerHost.d.ts +25 -0
  138. package/types/compilerHost.d.ts.map +1 -0
  139. package/types/constants.d.ts +0 -1
  140. package/types/constants.d.ts.map +1 -1
  141. package/types/domStructuralPass.d.ts +3 -0
  142. package/types/domStructuralPass.d.ts.map +1 -0
  143. package/types/exports.d.ts +3 -6
  144. package/types/exports.d.ts.map +1 -1
  145. package/types/extractor/addLocalExports.d.ts +3 -0
  146. package/types/extractor/addLocalExports.d.ts.map +1 -0
  147. package/types/extractor/bundle.d.ts +66 -65
  148. package/types/extractor/bundle.d.ts.map +1 -1
  149. package/types/extractor/bundleConfig.d.ts +19 -4
  150. package/types/extractor/bundleConfig.d.ts.map +1 -1
  151. package/types/extractor/esbuildAliasPlugin.d.ts.map +1 -1
  152. package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts +1 -1
  153. package/types/extractor/getTamaguiConfigPathFromOptionsConfig.d.ts.map +1 -1
  154. package/types/extractor/loadTamagui.d.ts +26 -3
  155. package/types/extractor/loadTamagui.d.ts.map +1 -1
  156. package/types/extractor/regenerateConfig.d.ts +1 -1
  157. package/types/extractor/regenerateConfig.d.ts.map +1 -1
  158. package/types/extractor/watchTamaguiConfig.d.ts.map +1 -1
  159. package/types/getPragmaOptions.d.ts +1 -1
  160. package/types/helpers/memoize.d.ts +1 -1
  161. package/types/helpers/memoize.d.ts.map +1 -1
  162. package/types/helpers/requireTamaguiCore.d.ts.map +1 -1
  163. package/types/index.d.ts.map +1 -1
  164. package/types/registerRequire.d.ts +2 -2
  165. package/types/registerRequire.d.ts.map +1 -1
  166. package/types/staticEvaluationIgnoredModules.d.ts +9 -0
  167. package/types/staticEvaluationIgnoredModules.d.ts.map +1 -0
  168. package/types/types.d.ts +2 -90
  169. package/types/types.d.ts.map +1 -1
  170. package/types/zero/artifact.d.ts +44 -0
  171. package/types/zero/artifact.d.ts.map +1 -0
  172. package/types/zero/graph.d.ts +139 -0
  173. package/types/zero/graph.d.ts.map +1 -0
  174. package/types/zero/identity.d.ts +33 -0
  175. package/types/zero/identity.d.ts.map +1 -0
  176. package/types/zero/index.d.ts +9 -0
  177. package/types/zero/index.d.ts.map +1 -0
  178. package/types/zero/islands.d.ts +56 -0
  179. package/types/zero/islands.d.ts.map +1 -0
  180. package/types/zero/options.d.ts +58 -0
  181. package/types/zero/options.d.ts.map +1 -0
  182. package/types/zero/ownership.d.ts +51 -0
  183. package/types/zero/ownership.d.ts.map +1 -0
  184. package/types/zero/theme.d.ts +83 -0
  185. package/types/zero/theme.d.ts.map +1 -0
  186. package/types/zero/transform.d.ts +53 -0
  187. package/types/zero/transform.d.ts.map +1 -0
  188. package/dist/check-dep-versions.cjs +0 -372
  189. package/dist/checkDeps.cjs +0 -271
  190. package/dist/constants.cjs +0 -51
  191. package/dist/exports.cjs +0 -48
  192. package/dist/extractor/accessSafe.cjs +0 -48
  193. package/dist/extractor/babelParse.cjs +0 -56
  194. package/dist/extractor/buildClassName.cjs +0 -86
  195. package/dist/extractor/bundle.cjs +0 -234
  196. package/dist/extractor/bundleConfig.cjs +0 -729
  197. package/dist/extractor/concatClassName.cjs +0 -129
  198. package/dist/extractor/createEvaluator.cjs +0 -88
  199. package/dist/extractor/createExtractor.cjs +0 -1968
  200. package/dist/extractor/createLogger.cjs +0 -50
  201. package/dist/extractor/detectModuleFormat.cjs +0 -55
  202. package/dist/extractor/ensureImportingConcat.cjs +0 -54
  203. package/dist/extractor/errors.cjs +0 -28
  204. package/dist/extractor/esbuildAliasPlugin.cjs +0 -56
  205. package/dist/extractor/esbuildTsconfigPaths.cjs +0 -108
  206. package/dist/extractor/evaluateAstNode.cjs +0 -128
  207. package/dist/extractor/extractHelpers.cjs +0 -182
  208. package/dist/extractor/extractMediaStyle.cjs +0 -169
  209. package/dist/extractor/extractToClassNames.cjs +0 -475
  210. package/dist/extractor/extractToNative.cjs +0 -369
  211. package/dist/extractor/findTopmostFunction.cjs +0 -43
  212. package/dist/extractor/generatedUid.cjs +0 -58
  213. package/dist/extractor/getPrefixLogs.cjs +0 -31
  214. package/dist/extractor/getPropValueFromAttributes.cjs +0 -85
  215. package/dist/extractor/getSourceModule.cjs +0 -100
  216. package/dist/extractor/getStaticBindingsForScope.cjs +0 -213
  217. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +0 -41
  218. package/dist/extractor/hasTopLevelAwait.cjs +0 -62
  219. package/dist/extractor/hoistClassNames.cjs +0 -76
  220. package/dist/extractor/literalToAst.cjs +0 -109
  221. package/dist/extractor/loadFile.cjs +0 -17
  222. package/dist/extractor/loadTamagui.cjs +0 -373
  223. package/dist/extractor/logLines.cjs +0 -43
  224. package/dist/extractor/normalizeTernaries.cjs +0 -100
  225. package/dist/extractor/propsToFontFamilyCache.cjs +0 -42
  226. package/dist/extractor/regenerateConfig.cjs +0 -178
  227. package/dist/extractor/removeUnusedHooks.cjs +0 -108
  228. package/dist/extractor/timer.cjs +0 -52
  229. package/dist/extractor/validHTMLAttributes.cjs +0 -79
  230. package/dist/extractor/watchTamaguiConfig.cjs +0 -70
  231. package/dist/getPragmaOptions.cjs +0 -73
  232. package/dist/helpers/memoize.cjs +0 -45
  233. package/dist/helpers/requireTamaguiCore.cjs +0 -40
  234. package/dist/index.cjs +0 -42
  235. package/dist/registerRequire.cjs +0 -209
  236. package/dist/server.cjs +0 -82
  237. package/dist/types.cjs +0 -18
  238. package/dist/worker.cjs +0 -111
  239. package/src/extractor/accessSafe.ts +0 -22
  240. package/src/extractor/babelParse.ts +0 -38
  241. package/src/extractor/buildClassName.ts +0 -76
  242. package/src/extractor/createEvaluator.ts +0 -82
  243. package/src/extractor/createExtractor.ts +0 -2970
  244. package/src/extractor/createLogger.ts +0 -41
  245. package/src/extractor/ensureImportingConcat.ts +0 -36
  246. package/src/extractor/errors.ts +0 -1
  247. package/src/extractor/evaluateAstNode.ts +0 -136
  248. package/src/extractor/extractHelpers.ts +0 -211
  249. package/src/extractor/extractMediaStyle.ts +0 -194
  250. package/src/extractor/extractToClassNames.ts +0 -733
  251. package/src/extractor/extractToNative.ts +0 -506
  252. package/src/extractor/findTopmostFunction.ts +0 -24
  253. package/src/extractor/generatedUid.ts +0 -41
  254. package/src/extractor/getPrefixLogs.ts +0 -9
  255. package/src/extractor/getPropValueFromAttributes.ts +0 -95
  256. package/src/extractor/getSourceModule.ts +0 -96
  257. package/src/extractor/getStaticBindingsForScope.ts +0 -237
  258. package/src/extractor/hasTopLevelAwait.ts +0 -28
  259. package/src/extractor/hoistClassNames.ts +0 -52
  260. package/src/extractor/literalToAst.ts +0 -85
  261. package/src/extractor/loadFile.ts +0 -17
  262. package/src/extractor/logLines.ts +0 -16
  263. package/src/extractor/normalizeTernaries.ts +0 -89
  264. package/src/extractor/propsToFontFamilyCache.ts +0 -18
  265. package/src/extractor/removeUnusedHooks.ts +0 -83
  266. package/src/extractor/timer.ts +0 -25
  267. package/src/extractor/validHTMLAttributes.ts +0 -52
  268. package/src/worker.ts +0 -142
  269. package/types/extractor/accessSafe.d.ts +0 -3
  270. package/types/extractor/accessSafe.d.ts.map +0 -1
  271. package/types/extractor/babelParse.d.ts +0 -5
  272. package/types/extractor/babelParse.d.ts.map +0 -1
  273. package/types/extractor/buildClassName.d.ts +0 -7
  274. package/types/extractor/buildClassName.d.ts.map +0 -1
  275. package/types/extractor/createEvaluator.d.ts +0 -12
  276. package/types/extractor/createEvaluator.d.ts.map +0 -1
  277. package/types/extractor/createExtractor.d.ts +0 -32
  278. package/types/extractor/createExtractor.d.ts.map +0 -1
  279. package/types/extractor/createLogger.d.ts +0 -3
  280. package/types/extractor/createLogger.d.ts.map +0 -1
  281. package/types/extractor/ensureImportingConcat.d.ts +0 -4
  282. package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
  283. package/types/extractor/errors.d.ts +0 -3
  284. package/types/extractor/errors.d.ts.map +0 -1
  285. package/types/extractor/evaluateAstNode.d.ts +0 -3
  286. package/types/extractor/evaluateAstNode.d.ts.map +0 -1
  287. package/types/extractor/extractHelpers.d.ts +0 -28
  288. package/types/extractor/extractHelpers.d.ts.map +0 -1
  289. package/types/extractor/extractMediaStyle.d.ts +0 -11
  290. package/types/extractor/extractMediaStyle.d.ts.map +0 -1
  291. package/types/extractor/extractToClassNames.d.ts +0 -25
  292. package/types/extractor/extractToClassNames.d.ts.map +0 -1
  293. package/types/extractor/extractToNative.d.ts +0 -13
  294. package/types/extractor/extractToNative.d.ts.map +0 -1
  295. package/types/extractor/findTopmostFunction.d.ts +0 -4
  296. package/types/extractor/findTopmostFunction.d.ts.map +0 -1
  297. package/types/extractor/generatedUid.d.ts +0 -5
  298. package/types/extractor/generatedUid.d.ts.map +0 -1
  299. package/types/extractor/getPrefixLogs.d.ts +0 -3
  300. package/types/extractor/getPrefixLogs.d.ts.map +0 -1
  301. package/types/extractor/getPropValueFromAttributes.d.ts +0 -19
  302. package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
  303. package/types/extractor/getSourceModule.d.ts +0 -16
  304. package/types/extractor/getSourceModule.d.ts.map +0 -1
  305. package/types/extractor/getStaticBindingsForScope.d.ts +0 -5
  306. package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
  307. package/types/extractor/hasTopLevelAwait.d.ts +0 -2
  308. package/types/extractor/hasTopLevelAwait.d.ts.map +0 -1
  309. package/types/extractor/hoistClassNames.d.ts +0 -6
  310. package/types/extractor/hoistClassNames.d.ts.map +0 -1
  311. package/types/extractor/literalToAst.d.ts +0 -4
  312. package/types/extractor/literalToAst.d.ts.map +0 -1
  313. package/types/extractor/loadFile.d.ts +0 -1
  314. package/types/extractor/loadFile.d.ts.map +0 -1
  315. package/types/extractor/logLines.d.ts +0 -2
  316. package/types/extractor/logLines.d.ts.map +0 -1
  317. package/types/extractor/normalizeTernaries.d.ts +0 -5
  318. package/types/extractor/normalizeTernaries.d.ts.map +0 -1
  319. package/types/extractor/propsToFontFamilyCache.d.ts +0 -4
  320. package/types/extractor/propsToFontFamilyCache.d.ts.map +0 -1
  321. package/types/extractor/removeUnusedHooks.d.ts +0 -3
  322. package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
  323. package/types/extractor/timer.d.ts +0 -5
  324. package/types/extractor/timer.d.ts.map +0 -1
  325. package/types/extractor/validHTMLAttributes.d.ts +0 -52
  326. package/types/extractor/validHTMLAttributes.d.ts.map +0 -1
  327. package/types/worker.d.ts +0 -46
  328. package/types/worker.d.ts.map +0 -1
  329. /package/dist/{setup.cjs → cjs/setup.cjs} +0 -0
@@ -1,1968 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
34
- var createExtractor_exports = {};
35
- __export(createExtractor_exports, {
36
- createExtractor: () => createExtractor
37
- });
38
- module.exports = __toCommonJS(createExtractor_exports);
39
- var import_traverse = __toESM(require("@babel/traverse"));
40
- var t = __toESM(require("@babel/types"));
41
- var import_cli_color = require("@tamagui/cli-color");
42
- var reactNativeWebInternals = __toESM(require("@tamagui/react-native-web-internals"));
43
- var import_web = require("@tamagui/web");
44
- var import_node_fs = require("node:fs");
45
- var import_node_path = require("node:path");
46
- var import_typescript = require("typescript");
47
- var import_constants = require("../constants.cjs");
48
- var import_requireTamaguiCore = require("../helpers/requireTamaguiCore.cjs");
49
- var import_createEvaluator = require("./createEvaluator.cjs");
50
- var import_evaluateAstNode = require("./evaluateAstNode.cjs");
51
- var import_extractHelpers = require("./extractHelpers.cjs");
52
- var import_findTopmostFunction = require("./findTopmostFunction.cjs");
53
- var import_getStaticBindingsForScope = require("./getStaticBindingsForScope.cjs");
54
- var import_literalToAst = require("./literalToAst.cjs");
55
- var import_loadTamagui = require("./loadTamagui.cjs");
56
- var import_logLines = require("./logLines.cjs");
57
- var import_normalizeTernaries = require("./normalizeTernaries.cjs");
58
- var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
59
- var import_timer = require("./timer.cjs");
60
- var import_validHTMLAttributes = require("./validHTMLAttributes.cjs");
61
- var import_errors = require("./errors.cjs");
62
- var import_esbuildTsconfigPaths = require("./esbuildTsconfigPaths.cjs");
63
- const UNTOUCHED_PROPS = {
64
- key: true,
65
- style: true,
66
- className: true
67
- };
68
- const nativeOnlyPlatforms = /* @__PURE__ */new Set(["android", "ios", "tv", "androidtv", "tvos"]);
69
- const createTernary = x => x;
70
- let hasLoggedBaseInfo = false;
71
- function isFullyDisabled(props) {
72
- return props.disableExtraction && props.disableDebugAttr;
73
- }
74
- function hasUntilMeasuredAncestor(path, groupName) {
75
- let current = path.parentPath;
76
- while (current) {
77
- if (current.isJSXElement()) {
78
- const opening = current.node.openingElement;
79
- let foundGroup = false;
80
- let foundUntilMeasured = false;
81
- for (const attr of opening.attributes) {
82
- if (!t.isJSXAttribute(attr)) continue;
83
- if (!t.isJSXIdentifier(attr.name)) continue;
84
- const aName = attr.name.name;
85
- if (aName === "group") {
86
- if (t.isStringLiteral(attr.value) && attr.value.value === groupName) {
87
- foundGroup = true;
88
- } else if (t.isJSXExpressionContainer(attr.value) && t.isStringLiteral(attr.value.expression) && attr.value.expression.value === groupName) {
89
- foundGroup = true;
90
- }
91
- } else if (aName === "untilMeasured") {
92
- foundUntilMeasured = true;
93
- }
94
- }
95
- if (foundGroup && foundUntilMeasured) return true;
96
- }
97
- current = current.parentPath;
98
- }
99
- return false;
100
- }
101
- function createExtractor({
102
- logger = console,
103
- platform = "web"
104
- } = {
105
- logger: console
106
- }) {
107
- const INLINE_EXTRACTABLE = {
108
- ref: "ref",
109
- key: "key",
110
- ...(platform === "web" && {
111
- onPress: "onClick",
112
- onHoverIn: "onMouseEnter",
113
- onHoverOut: "onMouseLeave",
114
- onPressIn: "onMouseDown",
115
- onPressOut: "onMouseUp"
116
- }),
117
- ...(platform === "native" && {
118
- // native view props that should pass through without preventing flattening
119
- testID: "testID",
120
- nativeID: "nativeID",
121
- accessibilityLabel: "accessibilityLabel",
122
- accessibilityHint: "accessibilityHint",
123
- accessibilityRole: "accessibilityRole",
124
- accessibilityState: "accessibilityState",
125
- accessibilityValue: "accessibilityValue",
126
- accessibilityActions: "accessibilityActions",
127
- accessibilityLabelledBy: "accessibilityLabelledBy",
128
- accessibilityLiveRegion: "accessibilityLiveRegion",
129
- accessibilityElementsHidden: "accessibilityElementsHidden",
130
- accessibilityViewIsModal: "accessibilityViewIsModal",
131
- importantForAccessibility: "importantForAccessibility",
132
- collapsable: "collapsable",
133
- needsOffscreenAlphaCompositing: "needsOffscreenAlphaCompositing",
134
- removeClippedSubviews: "removeClippedSubviews",
135
- renderToHardwareTextureAndroid: "renderToHardwareTextureAndroid",
136
- shouldRasterizeIOS: "shouldRasterizeIOS",
137
- hitSlop: "hitSlop",
138
- pointerEvents: "pointerEvents"
139
- })
140
- };
141
- const componentState = {
142
- focus: false,
143
- focusVisible: false,
144
- focusWithin: false,
145
- hover: false,
146
- unmounted: true,
147
- press: false,
148
- pressIn: false,
149
- disabled: false
150
- };
151
- const styleProps = {
152
- resolveValues: platform === "native" ? "value" : "variable",
153
- noClass: false,
154
- isAnimated: false
155
- };
156
- const shouldAddDebugProp =
157
- // really basic disable this for next.js because it messes with ssr
158
- !process.env.npm_package_dependencies_next && platform !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.IDENTIFY_TAGS);
159
- let projectInfo = null;
160
- const dynamicComponentCache = /* @__PURE__ */new Map();
161
- const dynamicLoadingInProgress = /* @__PURE__ */new Set();
162
- let _compilerOptions = null;
163
- function getCompilerOptions() {
164
- if (!_compilerOptions) {
165
- try {
166
- _compilerOptions = (0, import_esbuildTsconfigPaths.loadCompilerOptionsFromTsconfig)();
167
- } catch {
168
- _compilerOptions = {};
169
- }
170
- }
171
- return _compilerOptions;
172
- }
173
- function resolveImportPath(fromFile, importPath) {
174
- if (importPath.startsWith(".")) {
175
- const dir = (0, import_node_path.dirname)(fromFile);
176
- const base = (0, import_node_path.resolve)(dir, importPath);
177
- const extensions = [".tsx", ".ts", ".jsx", ".js"];
178
- for (const ext of extensions) {
179
- const full = base + ext;
180
- if ((0, import_node_fs.existsSync)(full)) return full;
181
- }
182
- for (const ext of extensions) {
183
- const full = (0, import_node_path.resolve)(base, `index${ext}`);
184
- if ((0, import_node_fs.existsSync)(full)) return full;
185
- }
186
- return null;
187
- }
188
- const compilerOptions = getCompilerOptions();
189
- if (compilerOptions.paths) {
190
- try {
191
- const {
192
- resolvedModule
193
- } = (0, import_typescript.nodeModuleNameResolver)(importPath, fromFile, compilerOptions, import_typescript.sys);
194
- if (resolvedModule && !resolvedModule.resolvedFileName.endsWith(".d.ts") && !resolvedModule.isExternalLibraryImport) {
195
- return resolvedModule.resolvedFileName;
196
- }
197
- } catch {}
198
- }
199
- return null;
200
- }
201
- const styledCheckCache = /* @__PURE__ */new Map();
202
- function mightHaveStyledComponents(filePath) {
203
- const cached = styledCheckCache.get(filePath);
204
- if (cached !== void 0) return cached;
205
- try {
206
- const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
207
- const result = content.includes("styled(");
208
- styledCheckCache.set(filePath, result);
209
- return result;
210
- } catch {
211
- styledCheckCache.set(filePath, false);
212
- return false;
213
- }
214
- }
215
- function loadSync(props) {
216
- if (isFullyDisabled(props)) {
217
- return null;
218
- }
219
- return projectInfo ||= (0, import_loadTamagui.loadTamaguiSync)(props);
220
- }
221
- async function load(props) {
222
- if (isFullyDisabled(props)) {
223
- return null;
224
- }
225
- return projectInfo ||= await (0, import_loadTamagui.loadTamagui)(props);
226
- }
227
- return {
228
- options: {
229
- logger
230
- },
231
- cleanupBeforeExit: import_getStaticBindingsForScope.cleanupBeforeExit,
232
- loadTamagui: load,
233
- loadTamaguiSync: loadSync,
234
- getTamagui() {
235
- return projectInfo?.tamaguiConfig;
236
- },
237
- parseSync: (f, props) => {
238
- globalThis.expo ||= {};
239
- const projectInfo2 = loadSync(props);
240
- return parseWithConfig(projectInfo2 || {}, f, props);
241
- },
242
- parse: async (f, props) => {
243
- globalThis.expo ||= {};
244
- const projectInfo2 = await load(props);
245
- return parseWithConfig(projectInfo2 || {}, f, props);
246
- }
247
- };
248
- function parseWithConfig({
249
- components,
250
- tamaguiConfig
251
- }, fileOrPath, options) {
252
- const {
253
- config = "tamagui.config.ts",
254
- importsWhitelist = ["constants.js"],
255
- evaluateVars = true,
256
- sourcePath = "",
257
- onExtractTag,
258
- onStyledDefinitionRule,
259
- getFlattenedNode,
260
- disable,
261
- disableExtraction,
262
- disableExtractVariables,
263
- disableDebugAttr,
264
- enableDynamicEvaluation = false,
265
- includeExtensions = [".ts", ".tsx", ".jsx"],
266
- extractStyledDefinitions = false,
267
- prefixLogs,
268
- excludeProps,
269
- platform: platform2,
270
- ...restProps
271
- } = options;
272
- if (sourcePath && dynamicComponentCache.has(sourcePath)) {
273
- dynamicComponentCache.delete(sourcePath);
274
- styledCheckCache.delete(sourcePath);
275
- }
276
- if (sourcePath.includes(".tamagui-dynamic-eval")) {
277
- return null;
278
- }
279
- const {
280
- normalizeStyle,
281
- getSplitStyles,
282
- mediaQueryConfig,
283
- propMapper,
284
- proxyThemeVariables,
285
- getDefaultProps,
286
- pseudoDescriptors
287
- } = (0, import_requireTamaguiCore.requireTamaguiCore)(platform2);
288
- let shouldPrintDebug = options.shouldPrintDebug || false;
289
- if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
290
- return null;
291
- }
292
- if (!isFullyDisabled(options)) {
293
- if (!components) {
294
- throw new Error(`Must provide components`);
295
- }
296
- }
297
- if (sourcePath && includeExtensions && !includeExtensions.some(ext => sourcePath.endsWith(ext))) {
298
- if (shouldPrintDebug) {
299
- logger.info(`Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(", ")}`);
300
- }
301
- return null;
302
- }
303
- function isValidStyleKey(name, staticConfig) {
304
- if (!projectInfo) {
305
- throw new Error(`Tamagui extractor not loaded yet`);
306
- }
307
- if (platform2 === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
308
- return false;
309
- }
310
- if (name[0] === "$") {
311
- const mediaName = name.slice(1);
312
- if (mediaName.startsWith("theme-") || mediaName.startsWith("platform-") || mediaName.startsWith("group-")) {
313
- return true;
314
- }
315
- if (mediaQueryConfig[mediaName]) {
316
- return true;
317
- }
318
- }
319
- return !!(staticConfig.validStyles?.[name] || pseudoDescriptors[name] ||
320
- // don't disable variants or else you lose many things flattening
321
- staticConfig.variants?.[name] || projectInfo?.tamaguiConfig?.shorthands[name]);
322
- }
323
- function getGroupPseudo(name) {
324
- const [_, groupName, a, b, c] = name.split("-");
325
- if (!groupName) return;
326
- const m2 = a && b ? `${a}-${b}` : "";
327
- const media = m2 && mediaQueryConfig[m2] && m2 || a && mediaQueryConfig[a] && a;
328
- return media ? media === m2 ? c : b ? `${b}${c ? `-${c}` : ""}` : void 0 : a ? `${a}${b ? `-${b}` : ""}${c ? `-${c}` : ""}` : void 0;
329
- }
330
- const isTargetingHTML = platform2 === "web";
331
- const ogDebug = shouldPrintDebug;
332
- const tm = (0, import_timer.timer)();
333
- const propsWithFileInfo = {
334
- ...options,
335
- sourcePath,
336
- allLoadedComponents: components ? [...components] : []
337
- };
338
- if (!hasLoggedBaseInfo) {
339
- hasLoggedBaseInfo = true;
340
- if (shouldPrintDebug) {
341
- logger.info(["loaded components:", propsWithFileInfo.allLoadedComponents.map(comp => Object.keys(comp.nameToInfo).join(", ")).join(", ")].join(" "));
342
- }
343
- if (process.env.DEBUG?.startsWith("tamagui")) {
344
- logger.info(["loaded:", propsWithFileInfo.allLoadedComponents.map(x => x.moduleName)].join("\n"));
345
- }
346
- }
347
- tm.mark("load-tamagui", !!shouldPrintDebug);
348
- if (!isFullyDisabled(options)) {
349
- if (!tamaguiConfig?.themes) {
350
- console.error(`\u26D4\uFE0F Error: Missing "themes" in your tamagui.config file:
351
-
352
- You may not need the compiler! Remember you can run Tamagui with no configuration at all.
353
-
354
- You may have not "export default" your config (you can also "export const config").
355
-
356
- Or this may be due to duplicated dependency versions:
357
- - try out https://github.com/bmish/check-dependency-version-consistency to see if there are mis-matches.
358
- - or search your lockfile for mis-matches.
359
- `);
360
- console.info(` Got config:`, tamaguiConfig);
361
- process.exit(0);
362
- }
363
- }
364
- const firstThemeName = Object.keys(tamaguiConfig?.themes || {})[0];
365
- const firstTheme = tamaguiConfig?.themes[firstThemeName] || {};
366
- if (!firstTheme || typeof firstTheme !== "object") {
367
- const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`;
368
- console.info(err, `Got config:`, tamaguiConfig);
369
- console.info(`Looking for theme:`, firstThemeName);
370
- throw new Error(err);
371
- }
372
- const proxiedTheme = proxyThemeVariables(firstTheme);
373
- const themeAccessListeners = /* @__PURE__ */new Set();
374
- const defaultTheme = new Proxy(proxiedTheme, {
375
- get(target, key) {
376
- if (Reflect.has(target, key)) {
377
- themeAccessListeners.forEach(cb => cb(String(key)));
378
- }
379
- return Reflect.get(target, key);
380
- }
381
- });
382
- const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
383
- if (!isFullyDisabled(options)) {
384
- if (Object.keys(components || []).length === 0) {
385
- console.warn(`Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)`);
386
- if (process.env.DEBUG === "tamagui") {
387
- console.info(`components`, Object.keys(components || []), components);
388
- }
389
- }
390
- }
391
- if (shouldPrintDebug === "verbose") {
392
- logger.info(`allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map(k => k.moduleName).join(", ")}`);
393
- logger.info(`valid import paths: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))}`);
394
- }
395
- let doesUseValidImport = false;
396
- let hasImportedTheme = false;
397
- const importDeclarations = [];
398
- for (const bodyPath of body) {
399
- if (bodyPath.type !== "ImportDeclaration") continue;
400
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
401
- const moduleName = node.source.value;
402
- const valid = (0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName);
403
- if (valid) {
404
- importDeclarations.push(node);
405
- }
406
- if (shouldPrintDebug === "verbose") {
407
- logger.info(` - import via ${moduleName} ${valid}`);
408
- }
409
- if (extractStyledDefinitions && enableDynamicEvaluation) {
410
- if (node.specifiers.some(specifier => specifier.local.name === "styled")) {
411
- doesUseValidImport = true;
412
- }
413
- }
414
- if (valid) {
415
- const names = node.specifiers.map(specifier => specifier.local.name);
416
- const isValidComponent = names.some(name => Boolean((0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, name)));
417
- if (shouldPrintDebug === "verbose") {
418
- logger.info(` - import ${isValidComponent ? "\u2705" : "\u21E3"} - ${names.join(", ")} via package '${moduleName}' - (valid: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))})`);
419
- }
420
- if (isValidComponent) {
421
- doesUseValidImport = true;
422
- if (!(extractStyledDefinitions && enableDynamicEvaluation)) break;
423
- }
424
- }
425
- }
426
- if (shouldPrintDebug) {
427
- logger.info(`${JSON.stringify({
428
- doesUseValidImport,
429
- hasImportedTheme
430
- }, null, 2)}
431
- `);
432
- }
433
- if (!doesUseValidImport && extractStyledDefinitions && enableDynamicEvaluation && sourcePath) {
434
- for (const bodyPath of body) {
435
- if (bodyPath.type !== "ImportDeclaration") continue;
436
- const node = "node" in bodyPath ? bodyPath.node : bodyPath;
437
- const moduleName = node.source.value;
438
- const resolved = resolveImportPath(sourcePath, moduleName);
439
- if (!resolved) continue;
440
- if (dynamicComponentCache.has(resolved)) {
441
- doesUseValidImport = true;
442
- break;
443
- }
444
- if (mightHaveStyledComponents(resolved)) {
445
- doesUseValidImport = true;
446
- break;
447
- }
448
- }
449
- }
450
- if (!doesUseValidImport) {
451
- return null;
452
- }
453
- function getValidImportedComponent(componentName) {
454
- const importDeclaration = importDeclarations.find(dec => dec.specifiers.some(spec => spec.local.name === componentName));
455
- if (!importDeclaration) {
456
- return null;
457
- }
458
- return (0, import_extractHelpers.getValidImport)(propsWithFileInfo, importDeclaration.source.value, componentName);
459
- }
460
- tm.mark("import-check", !!shouldPrintDebug);
461
- let couldntParse = false;
462
- let didDynamicLoad = false;
463
- const modifiedComponents = /* @__PURE__ */new Set();
464
- const bindingCache = {};
465
- const callTraverse = a => {
466
- return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
467
- };
468
- const shouldDisableExtraction = disableExtraction === true || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
469
- let programPath = null;
470
- const res = {
471
- styled: 0,
472
- flattened: 0,
473
- optimized: 0,
474
- modified: 0,
475
- found: 0
476
- };
477
- const version = `${Math.random()}`;
478
- callTraverse({
479
- // @ts-ignore
480
- Program: {
481
- enter(path) {
482
- programPath = path;
483
- }
484
- },
485
- // styled() calls
486
- CallExpression(path) {
487
- if (disable || shouldDisableExtraction || extractStyledDefinitions === false) {
488
- return;
489
- }
490
- if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
491
- return;
492
- }
493
- const variableName = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
494
- if (shouldPrintDebug) {
495
- logger.info(` [styled] Found styled(${variableName})`);
496
- }
497
- const parentNode = path.node.arguments[0];
498
- if (!t.isIdentifier(parentNode)) {
499
- return;
500
- }
501
- const parentName = parentNode.name;
502
- const definition = path.node.arguments[1];
503
- if (!parentName || !definition || !t.isObjectExpression(definition)) {
504
- return;
505
- }
506
- let Component = getValidImportedComponent(parentName) || getValidImportedComponent(variableName);
507
- const declaresVariants = !didDynamicLoad && definition.properties.some(prop => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "variants");
508
- if ((!Component || declaresVariants) && enableDynamicEvaluation) {
509
- didDynamicLoad = true;
510
- try {
511
- if (shouldPrintDebug) {
512
- logger.info(`Unknown component: ${variableName} = styled(${parentName}) attempting dynamic load: ${sourcePath}`);
513
- }
514
- const out2 = (0, import_loadTamagui.loadTamaguiSync)({
515
- forceExports: true,
516
- components: [sourcePath],
517
- cacheKey: version
518
- });
519
- if (out2?.components) {
520
- propsWithFileInfo.allLoadedComponents = [...propsWithFileInfo.allLoadedComponents, ...out2.components];
521
- Component = out2.components.flatMap(x => x.nameToInfo[variableName] ?? [])[0] || Component;
522
- if (!out2.cached) {
523
- const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
524
- if (foundNames) {
525
- (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Tamagui found dynamic components: ${foundNames}`);
526
- }
527
- }
528
- } else if (shouldPrintDebug) {
529
- logger.info(`Couldn't load, got ${out2}`);
530
- }
531
- } catch (err) {
532
- if (shouldPrintDebug) {
533
- logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=tamagui for more)`);
534
- }
535
- }
536
- }
537
- if (!Component) {
538
- if (shouldPrintDebug) {
539
- logger.info(` No component found`);
540
- }
541
- return;
542
- }
543
- const componentSkipProps = /* @__PURE__ */new Set([...(Component.staticConfig.inlineWhenUnflattened || []), ...(Component.staticConfig.inlineProps || []),
544
- // for now skip variants, will return to them
545
- "variants", "defaultVariants",
546
- // skip fontFamily its basically a "variant", important for theme use to be value always
547
- "fontFamily", "name", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle", "hoverStyle", "pressStyle"]);
548
- const skipped = /* @__PURE__ */new Set();
549
- const styles = {};
550
- const staticDefaultProps = {};
551
- const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
552
- const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
553
- props: propsWithFileInfo,
554
- staticNamespace,
555
- sourcePath,
556
- shouldPrintDebug
557
- });
558
- const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
559
- for (const property of definition.properties) {
560
- if (t.isObjectProperty(property) && (t.isIdentifier(property.key) || t.isStringLiteral(property.key))) {
561
- const key = t.isIdentifier(property.key) ? property.key.name : property.key.value;
562
- const defaultPropValue = attemptEvalSafe(property.value);
563
- if (defaultPropValue !== import_constants.FAILED_EVAL) {
564
- staticDefaultProps[key] = defaultPropValue;
565
- }
566
- }
567
- if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) ||
568
- // TODO make pseudos and variants work
569
- // skip pseudos
570
- pseudoDescriptors[property.key.name] ||
571
- // skip variants
572
- Component.staticConfig.variants?.[property.key.name] || componentSkipProps.has(property.key.name)) {
573
- skipped.add(property);
574
- continue;
575
- }
576
- const out2 = attemptEvalSafe(property.value);
577
- if (out2 === import_constants.FAILED_EVAL) {
578
- skipped.add(property);
579
- } else {
580
- styles[property.key.name] = out2;
581
- }
582
- }
583
- const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, "", componentState, styleProps, void 0, void 0, void 0, void 0, false, shouldPrintDebug);
584
- const classNames = {
585
- ...out.classNames
586
- };
587
- if (shouldPrintDebug) {
588
- logger.info([`Extracted styled(${variableName})
589
- `, JSON.stringify(styles, null, 2), "\n classNames:", JSON.stringify(classNames, null, 2), "\n rulesToInsert:", out.rulesToInsert].join(" "));
590
- }
591
- if (out.rulesToInsert) {
592
- for (const key in out.rulesToInsert) {
593
- const styleObject = out.rulesToInsert[key];
594
- onStyledDefinitionRule?.(styleObject[import_web.StyleObjectIdentifier], styleObject[import_web.StyleObjectRules]);
595
- }
596
- }
597
- res.styled++;
598
- if (extractStyledDefinitions && enableDynamicEvaluation && Component) {
599
- const dynamicStaticConfig = {
600
- ...Component.staticConfig,
601
- defaultProps: {
602
- ...Component.staticConfig.defaultProps,
603
- ...staticDefaultProps
604
- }
605
- };
606
- propsWithFileInfo.allLoadedComponents.push({
607
- moduleName: "",
608
- nameToInfo: {
609
- [variableName]: {
610
- staticConfig: dynamicStaticConfig
611
- }
612
- }
613
- });
614
- if (sourcePath) {
615
- let existing = dynamicComponentCache.get(sourcePath);
616
- if (!existing) {
617
- existing = {
618
- moduleName: sourcePath,
619
- nameToInfo: {}
620
- };
621
- dynamicComponentCache.set(sourcePath, existing);
622
- }
623
- existing.nameToInfo[variableName] = {
624
- staticConfig: dynamicStaticConfig
625
- };
626
- }
627
- }
628
- if (shouldPrintDebug) {
629
- logger.info(`Extracted styled(${variableName})`);
630
- }
631
- },
632
- JSXElement(traversePath) {
633
- tm.mark("jsx-element", !!shouldPrintDebug);
634
- const node = traversePath.node.openingElement;
635
- const ogAttributes = node.attributes.map(attr => ({
636
- ...attr
637
- }));
638
- const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
639
- const closingElement = traversePath.node.closingElement;
640
- if (closingElement && t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
641
- if (shouldPrintDebug) {
642
- logger.info(` skip non-identifier element`);
643
- }
644
- return;
645
- }
646
- const binding = traversePath.scope.getBinding(node.name.name);
647
- let moduleName = "";
648
- let dynamicComponent = null;
649
- if (binding) {
650
- if (t.isImportDeclaration(binding.path.parent)) {
651
- moduleName = binding.path.parent.source.value;
652
- if (!(0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, binding.identifier.name)) {
653
- if (enableDynamicEvaluation && sourcePath) {
654
- const resolved = resolveImportPath(sourcePath, moduleName);
655
- if (resolved) {
656
- const cached = dynamicComponentCache.get(resolved);
657
- if (cached?.nameToInfo[binding.identifier.name]) {
658
- dynamicComponent = cached.nameToInfo[binding.identifier.name];
659
- } else if (!dynamicLoadingInProgress.has(resolved) && mightHaveStyledComponents(resolved)) {
660
- dynamicLoadingInProgress.add(resolved);
661
- try {
662
- const out = (0, import_loadTamagui.loadTamaguiSync)({
663
- forceExports: true,
664
- components: [resolved]
665
- });
666
- if (out?.components) {
667
- for (const comp of out.components) {
668
- let existing = dynamicComponentCache.get(resolved);
669
- if (!existing) {
670
- existing = {
671
- moduleName: resolved,
672
- nameToInfo: {}
673
- };
674
- dynamicComponentCache.set(resolved, existing);
675
- }
676
- Object.assign(existing.nameToInfo, comp.nameToInfo);
677
- propsWithFileInfo.allLoadedComponents.push({
678
- moduleName: resolved,
679
- nameToInfo: comp.nameToInfo
680
- });
681
- }
682
- const cachedNow = dynamicComponentCache.get(resolved);
683
- if (cachedNow?.nameToInfo[binding.identifier.name]) {
684
- dynamicComponent = cachedNow.nameToInfo[binding.identifier.name];
685
- }
686
- }
687
- } catch (err) {
688
- if (shouldPrintDebug) {
689
- logger.info(` - Failed to dynamically load ${resolved}: ${err}`);
690
- }
691
- } finally {
692
- dynamicLoadingInProgress.delete(resolved);
693
- }
694
- }
695
- }
696
- }
697
- if (!dynamicComponent) {
698
- if (shouldPrintDebug) {
699
- logger.info(` - Binding in component ${componentName} not valid import: "${binding.identifier.name}" isn't in ${moduleName}
700
- `);
701
- }
702
- return;
703
- }
704
- }
705
- }
706
- }
707
- const component = dynamicComponent || (0, import_extractHelpers.getValidComponent)(propsWithFileInfo, moduleName, node.name.name);
708
- if (!component || !component.staticConfig) {
709
- if (shouldPrintDebug) {
710
- logger.info(`
711
- - No Tamagui conf for: ${node.name.name}
712
- `);
713
- }
714
- return;
715
- }
716
- const originalNodeName = node.name.name;
717
- res.found++;
718
- const filePath = `./${(0, import_node_path.relative)(process.cwd(), sourcePath)}`;
719
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
720
- const codePosition = `${filePath}:${lineNumbers}`;
721
- const debugPropValue = node.attributes.filter(n => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map(n => {
722
- if (n.value === null) return true;
723
- if (t.isStringLiteral(n.value)) return n.value.value;
724
- return false;
725
- })[0];
726
- if (debugPropValue) {
727
- shouldPrintDebug = debugPropValue;
728
- }
729
- if (shouldPrintDebug) {
730
- logger.info(`\x1B[33m\x1B[0m ${componentName} | ${codePosition} -------------------`);
731
- logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
732
- }
733
- if (platform2 !== "native") {
734
- if (shouldAddDebugProp && !disableDebugAttr) {
735
- res.modified++;
736
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name)));
737
- if (componentName) {
738
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName)));
739
- }
740
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-at"), t.stringLiteral(`${(0, import_node_path.basename)(filePath)}:${lineNumbers}`)));
741
- }
742
- }
743
- if (shouldDisableExtraction) {
744
- if (shouldPrintDebug === "verbose") {
745
- logger.info(` \u274C Extraction disabled: ${JSON.stringify(disableExtraction)}
746
- `);
747
- }
748
- return;
749
- }
750
- try {
751
- let evaluateAttribute = function (path) {
752
- const attribute = path.node;
753
- const attr = {
754
- type: "attr",
755
- value: attribute
756
- };
757
- if (t.isJSXSpreadAttribute(attribute)) {
758
- const arg = attribute.argument;
759
- const conditional = t.isConditionalExpression(arg) ?
760
- // <YStack {...isSmall ? { color: 'red } : { color: 'blue }}
761
- [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ?
762
- // <YStack {...isSmall && { color: 'red }}
763
- [arg.left, arg.right, null] : null;
764
- if (conditional) {
765
- const [test, alt, cons] = conditional;
766
- if (!test) throw new Error(`no test`);
767
- if ([alt, cons].some(side => side && !isStaticObject(side))) {
768
- if (shouldPrintDebug) {
769
- logger.info(`not extractable ${alt} ${cons}`);
770
- }
771
- return attr;
772
- }
773
- return [...(flattenNestedTernaries(test, alt) || []), ...(cons && flattenNestedTernaries(t.unaryExpression("!", test), cons) || [])].map(ternary => ({
774
- type: "ternary",
775
- value: ternary
776
- }));
777
- }
778
- }
779
- if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
780
- if (shouldPrintDebug) {
781
- logger.info(" ! inlining, spread attr");
782
- }
783
- inlined.set(`${Math.random()}`, "spread");
784
- return attr;
785
- }
786
- const name = attribute.name.name;
787
- if (name === "style") {
788
- shouldDeopt = true;
789
- return null;
790
- }
791
- if (excludeProps?.has(name)) {
792
- if (shouldPrintDebug) {
793
- logger.info([" excluding prop", name].join(" "));
794
- }
795
- return null;
796
- }
797
- if (inlineProps.has(name)) {
798
- inlined.set(name, name);
799
- if (shouldPrintDebug) {
800
- logger.info([" ! inlining, inline prop", name].join(" "));
801
- }
802
- return attr;
803
- }
804
- if (UNTOUCHED_PROPS[name]) {
805
- return attr;
806
- }
807
- if (INLINE_EXTRACTABLE[name]) {
808
- inlined.set(name, INLINE_EXTRACTABLE[name]);
809
- return attr;
810
- }
811
- if (name.startsWith("data-") || name.startsWith("aria-") || import_validHTMLAttributes.validHTMLAttributes[name]) {
812
- return attr;
813
- }
814
- if ((name === "enterStyle" || name === "exitStyle") && t.isJSXExpressionContainer(attribute?.value)) {
815
- shouldDeopt = true;
816
- return attr;
817
- }
818
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
819
- const shortname = name.slice(1);
820
- if (mediaQueryConfig[shortname]) {
821
- const expression = attribute.value.expression;
822
- if (!t.isJSXEmptyExpression(expression)) {
823
- const ternaries2 = flattenNestedTernaries(t.stringLiteral(shortname), expression, {
824
- inlineMediaQuery: shortname
825
- });
826
- if (ternaries2) {
827
- return ternaries2.map(value2 => ({
828
- type: "ternary",
829
- value: value2
830
- }));
831
- }
832
- }
833
- }
834
- }
835
- const [value, valuePath] = (() => {
836
- if (t.isJSXExpressionContainer(attribute?.value)) {
837
- return [attribute.value.expression, path.get("value")];
838
- }
839
- return [attribute.value, path.get("value")];
840
- })();
841
- if (deoptProps.has(name) || platform2 === "native" && name[0] === "$" && (name.startsWith("$theme-") || name.startsWith("$group-") && getGroupPseudo(name) !== "hover")) {
842
- inlined.set(name, true);
843
- return attr;
844
- }
845
- const remove = () => {
846
- Array.isArray(valuePath) ? valuePath.map(p => p.remove()) : valuePath.remove();
847
- };
848
- if (name === "ref") {
849
- if (shouldPrintDebug) {
850
- logger.info([" ! inlining, ref", name].join(" "));
851
- }
852
- inlined.set("ref", "ref");
853
- return attr;
854
- }
855
- if (name === "render") {
856
- if (!value || value.type !== "StringLiteral") {
857
- if (shouldPrintDebug) {
858
- logger.info(` ! deopt on render prop (not a string literal)`);
859
- }
860
- shouldDeopt = true;
861
- }
862
- return {
863
- type: "attr",
864
- value: path.node
865
- };
866
- }
867
- if (disableExtractVariables === true) {
868
- if (value) {
869
- if (value.type === "StringLiteral" && value.value[0] === "$") {
870
- if (shouldPrintDebug) {
871
- logger.info([` ! inlining, native disable extract: ${name} =`, value.value].join(" "));
872
- }
873
- inlined.set(name, true);
874
- return attr;
875
- }
876
- }
877
- }
878
- if (name === "theme") {
879
- inlined.set("theme", attr.value);
880
- return attr;
881
- }
882
- if (isTargetingHTML && name === "group" && t.isStringLiteral(value)) {
883
- return [];
884
- }
885
- const styleValue = attemptEvalSafe(value);
886
- if (name[0] === "$" && (name.startsWith("$theme-") || name.startsWith("$group-")) && styleValue && typeof styleValue === "object" && Object.keys(styleValue).some(k => k[0] === "$")) {
887
- if (shouldPrintDebug) {
888
- logger.info(` ! nested media-like key inside ${name}, deopt to runtime`);
889
- }
890
- inlined.set(name, true);
891
- return attr;
892
- }
893
- if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
894
- let out = null;
895
- propMapper(name, styleValue, propMapperStyleState, false, (key, val) => {
896
- out ||= {};
897
- out[key] = val;
898
- });
899
- if (out) {
900
- if (isTargetingHTML) {
901
- out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
902
- delete out.className;
903
- delete out.style;
904
- }
905
- }
906
- let didInline = false;
907
- const attributes = Object.keys(out).map(key => {
908
- const val = out[key];
909
- const isStyle = isValidStyleKey(key, staticConfig);
910
- if (isStyle) {
911
- return {
912
- type: "style",
913
- value: {
914
- [key]: styleValue
915
- },
916
- name: key,
917
- attr: path.node
918
- };
919
- }
920
- if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") ||
921
- // this is debug stuff added by vite / new jsx transform
922
- key === "__source" || key === "__self") {
923
- if (styleValue === import_constants.FAILED_EVAL && key !== name && t.isJSXAttribute(attr.value)) {
924
- return {
925
- type: "attr",
926
- value: t.jsxAttribute(t.jsxIdentifier(key), attr.value.value)
927
- };
928
- }
929
- return attr;
930
- }
931
- if (shouldPrintDebug) {
932
- logger.info(" ! inlining, non-static " + key);
933
- }
934
- didInline = true;
935
- inlined.set(key, val);
936
- return val;
937
- });
938
- if (didInline) {
939
- if (shouldPrintDebug) {
940
- logger.info(` bailing flattening due to attributes ${attributes.map(x => x.toString())}`);
941
- }
942
- return attr;
943
- }
944
- return attributes;
945
- }
946
- if (styleValue !== import_constants.FAILED_EVAL) {
947
- if (inlineWhenUnflattened.has(name)) {
948
- inlineWhenUnflattenedOGVals[name] = {
949
- styleValue,
950
- attr
951
- };
952
- }
953
- if (isValidStyleKey(name, staticConfig)) {
954
- if (name[0] === "$") {
955
- if (name.startsWith("$group-")) {
956
- const groupName = name.slice("$group-".length).split("-")[0];
957
- if (groupName && hasUntilMeasuredAncestor(path, groupName)) {
958
- if (shouldPrintDebug) {
959
- logger.info(` ! group="${groupName}" ancestor has untilMeasured, not flattening: ${name}`);
960
- }
961
- inlined.set(name, true);
962
- return attr;
963
- }
964
- }
965
- if (name.startsWith("$platform-")) {
966
- const platformName = name.slice(10);
967
- const isMatchingPlatform = platformName === platform2 || platformName === "native" && platform2 === "native" || platformName === "web" && platform2 === "web";
968
- if (isMatchingPlatform && typeof styleValue === "object") {
969
- if (shouldPrintDebug) {
970
- logger.info(` flattening $platform-${platformName}: ${JSON.stringify(styleValue)}`);
971
- }
972
- return Object.entries(styleValue).map(([key, val]) => ({
973
- type: "style",
974
- value: {
975
- [key]: val
976
- },
977
- name: key,
978
- attr: path.node
979
- }));
980
- } else {
981
- if (platform2 === "native" && nativeOnlyPlatforms.has(platformName)) {
982
- if (shouldPrintDebug) {
983
- logger.info(` ! keeping platform-specific style for runtime evaluation: ${name}`);
984
- }
985
- inlined.set(name, true);
986
- return attr;
987
- }
988
- if (shouldPrintDebug) {
989
- logger.info(` ! skipping non-matching platform style: ${name}`);
990
- }
991
- return [];
992
- }
993
- }
994
- }
995
- if (shouldPrintDebug) {
996
- logger.info(` style: ${name} = ${JSON.stringify(styleValue)}`);
997
- }
998
- if (!(name in defaultProps)) {
999
- if (!hasSetOptimized) {
1000
- res.optimized++;
1001
- hasSetOptimized = true;
1002
- }
1003
- }
1004
- return {
1005
- type: "style",
1006
- value: {
1007
- [name]: styleValue
1008
- },
1009
- name,
1010
- attr: path.node
1011
- };
1012
- }
1013
- if (variants[name]) {
1014
- variantValues.set(name, styleValue);
1015
- }
1016
- inlined.set(name, true);
1017
- return attr;
1018
- }
1019
- if (t.isBinaryExpression(value)) {
1020
- if (shouldPrintDebug) {
1021
- logger.info(` binary expression ${name} = ${value}`);
1022
- }
1023
- const {
1024
- operator,
1025
- left,
1026
- right
1027
- } = value;
1028
- const lVal = attemptEvalSafe(left);
1029
- const rVal = attemptEvalSafe(right);
1030
- if (shouldPrintDebug) {
1031
- logger.info(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
1032
- }
1033
- if (lVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
1034
- const ternary = addBinaryConditional(operator, left, right);
1035
- if (ternary) return ternary;
1036
- }
1037
- if (rVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(left)) {
1038
- const ternary = addBinaryConditional(operator, right, left);
1039
- if (ternary) return ternary;
1040
- }
1041
- if (shouldPrintDebug) {
1042
- logger.info(` evalBinaryExpression cant extract`);
1043
- }
1044
- inlined.set(name, true);
1045
- return attr;
1046
- }
1047
- const staticConditional = getStaticConditional(value);
1048
- if (staticConditional) {
1049
- if (shouldPrintDebug === "verbose") {
1050
- logger.info(` static conditional ${name} ${value}`);
1051
- }
1052
- return {
1053
- type: "ternary",
1054
- value: staticConditional
1055
- };
1056
- }
1057
- const staticLogical = getStaticLogical(value);
1058
- if (staticLogical) {
1059
- if (shouldPrintDebug === "verbose") {
1060
- logger.info(` static ternary ${name} = ${value}`);
1061
- }
1062
- return {
1063
- type: "ternary",
1064
- value: staticLogical
1065
- };
1066
- }
1067
- inlined.set(name, true);
1068
- if (shouldPrintDebug) {
1069
- logger.info(` ! inline no match ${name} ${value}`);
1070
- }
1071
- return attr;
1072
- function addBinaryConditional(operator, staticExpr, cond) {
1073
- if (getStaticConditional(cond)) {
1074
- const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
1075
- const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
1076
- if (shouldPrintDebug) {
1077
- logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
1078
- }
1079
- return {
1080
- type: "ternary",
1081
- value: {
1082
- test: cond.test,
1083
- remove,
1084
- alternate: {
1085
- [name]: alt
1086
- },
1087
- consequent: {
1088
- [name]: cons
1089
- }
1090
- }
1091
- };
1092
- }
1093
- return null;
1094
- }
1095
- function getStaticConditional(value2) {
1096
- if (t.isConditionalExpression(value2)) {
1097
- try {
1098
- const aVal = attemptEval(value2.alternate);
1099
- const cVal = attemptEval(value2.consequent);
1100
- if (shouldPrintDebug) {
1101
- const type = value2.test.type;
1102
- logger.info([" static ternary", type, cVal, aVal].join(" "));
1103
- }
1104
- return {
1105
- test: value2.test,
1106
- remove,
1107
- consequent: {
1108
- [name]: cVal
1109
- },
1110
- alternate: {
1111
- [name]: aVal
1112
- }
1113
- };
1114
- } catch (err) {
1115
- if (shouldPrintDebug) {
1116
- logger.info([" cant eval ternary", err.message].join(" "));
1117
- }
1118
- }
1119
- }
1120
- return null;
1121
- }
1122
- function getStaticLogical(value2) {
1123
- if (t.isLogicalExpression(value2)) {
1124
- if (value2.operator === "&&") {
1125
- try {
1126
- const val = attemptEval(value2.right);
1127
- if (shouldPrintDebug) {
1128
- logger.info([" staticLogical", value2.left, name, val].join(" "));
1129
- }
1130
- return {
1131
- test: value2.left,
1132
- remove,
1133
- consequent: {
1134
- [name]: val
1135
- },
1136
- alternate: null
1137
- };
1138
- } catch (err) {
1139
- if (shouldPrintDebug) {
1140
- logger.info([" cant static eval logical", err].join(" "));
1141
- }
1142
- }
1143
- }
1144
- }
1145
- return null;
1146
- }
1147
- },
1148
- isStaticObject = function (obj) {
1149
- return t.isObjectExpression(obj) && obj.properties.every(prop => {
1150
- if (!t.isObjectProperty(prop)) {
1151
- return false;
1152
- }
1153
- const propName = prop.key["name"];
1154
- if (!isValidStyleKey(propName, staticConfig) && propName !== "render") {
1155
- if (shouldPrintDebug) {
1156
- logger.info([" not a valid style prop!", propName].join(" "));
1157
- }
1158
- return false;
1159
- }
1160
- return true;
1161
- });
1162
- },
1163
- flattenNestedTernaries = function (test, side, ternaryPartial = {}) {
1164
- if (!side) {
1165
- return null;
1166
- }
1167
- if (!isStaticObject(side)) {
1168
- throw new Error("not extractable");
1169
- }
1170
- return side.properties.flatMap(property => {
1171
- if (!t.isObjectProperty(property)) {
1172
- throw new Error("expected object property");
1173
- }
1174
- if (t.isConditionalExpression(property.value)) {
1175
- const [truthy, falsy] = [t.objectExpression([t.objectProperty(property.key, property.value.consequent)]), t.objectExpression([t.objectProperty(property.key, property.value.alternate)])].map(x => attemptEval(x));
1176
- return [createTernary({
1177
- remove() {},
1178
- ...ternaryPartial,
1179
- test: t.logicalExpression("&&", test, property.value.test),
1180
- consequent: truthy,
1181
- alternate: null
1182
- }), createTernary({
1183
- ...ternaryPartial,
1184
- test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
1185
- consequent: falsy,
1186
- alternate: null,
1187
- remove() {}
1188
- })];
1189
- }
1190
- const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
1191
- const consequent = attemptEval(obj);
1192
- return createTernary({
1193
- remove() {},
1194
- ...ternaryPartial,
1195
- test,
1196
- consequent,
1197
- alternate: null
1198
- });
1199
- });
1200
- },
1201
- mergeToEnd = function (obj, key, val) {
1202
- if (key in obj) {
1203
- delete obj[key];
1204
- }
1205
- obj[key] = val;
1206
- },
1207
- normalizeStyleWithoutVariants = function (style) {
1208
- let res2 = {};
1209
- for (const key in style) {
1210
- if (staticConfig.variants && key in staticConfig.variants) {
1211
- mergeToEnd(res2, key, style[key]);
1212
- } else {
1213
- const expanded = normalizeStyle({
1214
- [key]: style[key]
1215
- }, true);
1216
- for (const key2 in expanded) {
1217
- mergeToEnd(res2, key2, expanded[key2]);
1218
- }
1219
- }
1220
- }
1221
- return res2;
1222
- },
1223
- mergeStyles = function (prev2, next) {
1224
- for (const key in next) {
1225
- if (pseudoDescriptors[key]) {
1226
- prev2[key] = prev2[key] || {};
1227
- Object.assign(prev2[key], next[key]);
1228
- } else {
1229
- mergeToEnd(prev2, key, next[key]);
1230
- }
1231
- }
1232
- };
1233
- const {
1234
- staticConfig
1235
- } = component;
1236
- const defaultProps = {
1237
- ...getDefaultProps(staticConfig)
1238
- };
1239
- const variants = staticConfig.variants || {};
1240
- const isTextView = staticConfig.isText || false;
1241
- const validStyles = staticConfig?.validStyles ?? {};
1242
- let tagName = defaultProps.render ?? (isTextView ? "span" : "div");
1243
- traversePath.get("openingElement").get("attributes").forEach(path => {
1244
- const attr = path.node;
1245
- if (t.isJSXSpreadAttribute(attr)) return;
1246
- if (attr.name.name !== "render") return;
1247
- const val = attr.value;
1248
- if (!t.isStringLiteral(val)) return;
1249
- tagName = val.value;
1250
- });
1251
- if (shouldPrintDebug === "verbose") {
1252
- console.info(` Start tag ${tagName}`);
1253
- }
1254
- const flatNodeName = getFlattenedNode?.({
1255
- isTextView,
1256
- tag: tagName
1257
- });
1258
- const inlineProps = /* @__PURE__ */new Set([
1259
- // adding some always inline props
1260
- ...(restProps.inlineProps || []), ...(staticConfig.inlineProps || [])]);
1261
- const canFlattenTransition = isTargetingHTML && tamaguiConfig?.animations.outputStyle === "css" && !tamaguiConfig.animationDrivers;
1262
- const deoptProps = /* @__PURE__ */new Set([
1263
- // css-only transitions lower to ordinary css; every runtime driver
1264
- // needs the component preserved so it can respond to prop changes.
1265
- "animation", ...(canFlattenTransition ? [] : ["transition"]), "animateOnly", "animatePresence", "disableOptimization", ...(!isTargetingHTML ? [
1266
- // native has no css pseudo selectors; these are runtime-only on
1267
- // rn (event listeners + style merge in createComponent), and if
1268
- // we let them flatten into the stylesheet they get written
1269
- // under a literal key that rn treats as an unknown style prop.
1270
- // hover is intentionally excluded: it is no-op on native and
1271
- // should be dropped rather than preserved as runtime work.
1272
- "pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"] : []),
1273
- // when using a non-CSS driver, de-opt on enterStyle/exitStyle
1274
- ...(tamaguiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]);
1275
- const inlineWhenUnflattened = new Set(staticConfig.inlineWhenUnflattened || []);
1276
- const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
1277
- const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
1278
- props: propsWithFileInfo,
1279
- staticNamespace,
1280
- sourcePath,
1281
- traversePath,
1282
- shouldPrintDebug
1283
- });
1284
- const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
1285
- if (shouldPrintDebug) {
1286
- logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
1287
- }
1288
- if (couldntParse) {
1289
- return;
1290
- }
1291
- tm.mark("jsx-element-flattened", !!shouldPrintDebug);
1292
- let attrs = [];
1293
- let shouldDeopt = false;
1294
- const inlined = /* @__PURE__ */new Map();
1295
- const variantValues = /* @__PURE__ */new Map();
1296
- let hasSetOptimized = false;
1297
- const inlineWhenUnflattenedOGVals = {};
1298
- const propMapperStyleState = {
1299
- staticConfig,
1300
- usedKeys: {},
1301
- classNames: {},
1302
- style: {},
1303
- theme: defaultTheme,
1304
- viewProps: defaultProps,
1305
- conf: tamaguiConfig,
1306
- props: defaultProps,
1307
- componentState,
1308
- styleProps: {
1309
- ...styleProps,
1310
- resolveValues: "auto"
1311
- },
1312
- debug: shouldPrintDebug
1313
- };
1314
- attrs = traversePath.get("openingElement").get("attributes").flatMap(path => {
1315
- if (shouldDeopt) {
1316
- return;
1317
- }
1318
- try {
1319
- const res2 = evaluateAttribute(path);
1320
- if (!res2) {
1321
- path.remove();
1322
- }
1323
- return res2;
1324
- } catch (err) {
1325
- if (shouldPrintDebug) {
1326
- logger.info(["Recoverable error extracting attribute", err.message, shouldPrintDebug === "verbose" ? err.stack : ""].join(" "));
1327
- if (shouldPrintDebug === "verbose") {
1328
- logger.info(`node ${path.node?.type}`);
1329
- }
1330
- }
1331
- inlined.set(`${Math.random()}`, "spread");
1332
- return {
1333
- type: "attr",
1334
- value: path.node
1335
- };
1336
- }
1337
- }).flat(4).filter(import_extractHelpers.isPresent);
1338
- if (shouldPrintDebug) {
1339
- logger.info([" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1340
- }
1341
- if (couldntParse || shouldDeopt) {
1342
- if (shouldPrintDebug) {
1343
- logger.info([` avoid optimizing:`, {
1344
- couldntParse,
1345
- shouldDeopt
1346
- }].join(" "));
1347
- }
1348
- node.attributes = ogAttributes;
1349
- return;
1350
- }
1351
- const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
1352
- if (parentFn) {
1353
- modifiedComponents.add(parentFn);
1354
- }
1355
- const hasSpread = attrs.some(x => x.type === "attr" && t.isJSXSpreadAttribute(x.value));
1356
- const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every(x => x.type === "JSXText"));
1357
- let themeVal = inlined.get("theme");
1358
- if (platform2 !== "native") {
1359
- inlined.delete("theme");
1360
- }
1361
- for (const [key] of inlined) {
1362
- const isStaticObjectVariant = staticConfig.variants?.[key] && variantValues.has(key);
1363
- if (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) {
1364
- inlined.delete(key);
1365
- }
1366
- }
1367
- const canFlattenProps = inlined.size === 0;
1368
- let shouldFlatten = Boolean(flatNodeName && !shouldDeopt && canFlattenProps && !hasSpread && !staticConfig.isStyledHOC && !staticConfig.isHOC && !staticConfig.isReactNative && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true));
1369
- const usedThemeKeys = /* @__PURE__ */new Set();
1370
- themeAccessListeners.add(key => {
1371
- if (disableExtractVariables) {
1372
- usedThemeKeys.add(key);
1373
- shouldFlatten = false;
1374
- if (shouldPrintDebug === "verbose") {
1375
- logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
1376
- }
1377
- }
1378
- });
1379
- if (!shouldFlatten) {
1380
- if (shouldPrintDebug) {
1381
- logger.info(`Deopting ${JSON.stringify({
1382
- shouldFlatten,
1383
- shouldDeopt,
1384
- canFlattenProps,
1385
- hasSpread,
1386
- neverFlatten: staticConfig.neverFlatten
1387
- })}`);
1388
- }
1389
- node.attributes = ogAttributes;
1390
- return;
1391
- }
1392
- let skipMap = false;
1393
- const defaultStyleAttrs = Object.keys(defaultProps).flatMap(key => {
1394
- if (skipMap) return [];
1395
- const value = defaultProps[key];
1396
- if (key === "theme" && !themeVal) {
1397
- if (platform2 === "native") {
1398
- shouldFlatten = false;
1399
- skipMap = true;
1400
- inlined.set("theme", {
1401
- value: t.stringLiteral(value)
1402
- });
1403
- }
1404
- themeVal = {
1405
- value: t.stringLiteral(value)
1406
- };
1407
- return [];
1408
- }
1409
- if (!isValidStyleKey(key, staticConfig)) {
1410
- return [];
1411
- }
1412
- const name = tamaguiConfig?.shorthands[key] || key;
1413
- if (value === void 0) {
1414
- logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
1415
- shouldDeopt = true;
1416
- return;
1417
- }
1418
- if (name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
1419
- defaultProps[key] = void 0;
1420
- return evaluateAttribute({
1421
- node: t.jsxAttribute(t.jsxIdentifier(name), t.jsxExpressionContainer(t.objectExpression(Object.keys(value).filter(k => {
1422
- return typeof value[k] !== "undefined";
1423
- }).map(k => {
1424
- return t.objectProperty(t.identifier(k), (0, import_literalToAst.literalToAst)(value[k]));
1425
- }))))
1426
- });
1427
- }
1428
- const attr = {
1429
- type: "style",
1430
- name,
1431
- value: {
1432
- [name]: value
1433
- }
1434
- };
1435
- return attr;
1436
- });
1437
- if (!skipMap) {
1438
- if (defaultStyleAttrs.length) {
1439
- attrs = [...defaultStyleAttrs, ...attrs];
1440
- }
1441
- }
1442
- let ternaries = [];
1443
- attrs = attrs.reduce((out, cur) => {
1444
- const next = attrs[attrs.indexOf(cur) + 1];
1445
- if (cur.type === "ternary") {
1446
- ternaries.push(cur.value);
1447
- }
1448
- if ((!next || next.type !== "ternary") && ternaries.length) {
1449
- const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map(({
1450
- alternate,
1451
- consequent,
1452
- ...rest
1453
- }) => {
1454
- return {
1455
- type: "ternary",
1456
- value: {
1457
- ...rest,
1458
- alternate: alternate || null,
1459
- consequent: consequent || null
1460
- }
1461
- };
1462
- });
1463
- try {
1464
- return [...out, ...normalized];
1465
- } finally {
1466
- if (shouldPrintDebug) {
1467
- logger.info(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
1468
- }
1469
- ternaries = [];
1470
- }
1471
- }
1472
- if (cur.type === "ternary") {
1473
- return out;
1474
- }
1475
- out.push(cur);
1476
- return out;
1477
- }, []).flat();
1478
- const ternaryBranchProps = /* @__PURE__ */new Map();
1479
- const allTernaries = attrs.flatMap(attr => attr.type === "ternary" ? attr.value : []);
1480
- if (allTernaries.length > 1) {
1481
- for (const ternary of (0, import_normalizeTernaries.normalizeTernaries)(allTernaries)) {
1482
- ternaryBranchProps.set((0, import_normalizeTernaries.getTernaryKey)(ternary.test), ternary);
1483
- }
1484
- }
1485
- if (themeVal) {
1486
- if (!programPath) {
1487
- console.warn(`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`);
1488
- } else {
1489
- if (shouldPrintDebug) {
1490
- logger.info([" - wrapping theme", themeVal].join(" "));
1491
- }
1492
- attrs = attrs.filter(x => !(x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme"));
1493
- if (!hasImportedTheme) {
1494
- hasImportedTheme = true;
1495
- programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/web")));
1496
- }
1497
- traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
1498
- }
1499
- }
1500
- if (shouldPrintDebug) {
1501
- logger.info([" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1502
- }
1503
- let foundStaticProps = {};
1504
- for (const key in attrs) {
1505
- const cur = attrs[key];
1506
- if (cur.type === "style") {
1507
- const expanded = normalizeStyleWithoutVariants(cur.value);
1508
- for (const key2 in expanded) {
1509
- mergeToEnd(foundStaticProps, key2, expanded[key2]);
1510
- }
1511
- continue;
1512
- }
1513
- if (cur.type === "attr") {
1514
- if (t.isJSXSpreadAttribute(cur.value)) {
1515
- continue;
1516
- }
1517
- if (!t.isJSXIdentifier(cur.value.name)) {
1518
- continue;
1519
- }
1520
- const key2 = cur.value.name.name;
1521
- const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1522
- if (value !== import_constants.FAILED_EVAL) {
1523
- mergeToEnd(foundStaticProps, key2, value);
1524
- }
1525
- }
1526
- }
1527
- const completeProps = {};
1528
- for (const key in defaultProps) {
1529
- if (!(key in foundStaticProps)) {
1530
- completeProps[key] = defaultProps[key];
1531
- }
1532
- }
1533
- for (const key in foundStaticProps) {
1534
- completeProps[key] = foundStaticProps[key];
1535
- }
1536
- attrs = attrs.reduce((acc, cur) => {
1537
- if (!cur) return acc;
1538
- if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
1539
- if (shouldFlatten) {
1540
- const name = cur.value.name.name;
1541
- if (typeof name === "string") {
1542
- if (name === "render") {
1543
- return acc;
1544
- }
1545
- if (variants[name] && variantValues.has(name)) {
1546
- const styleState = {
1547
- ...propMapperStyleState,
1548
- props: completeProps
1549
- };
1550
- let out = {};
1551
- propMapper(name, variantValues.get(name), styleState, false, (key2, val) => {
1552
- out[key2] = val;
1553
- });
1554
- if (out && isTargetingHTML) {
1555
- const cn = out.className;
1556
- out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
1557
- out.className = cn;
1558
- delete out.style;
1559
- }
1560
- if (shouldPrintDebug) {
1561
- logger.info([" - expanded variant", name, out].join(" "));
1562
- }
1563
- for (const key2 in out) {
1564
- const value2 = out[key2];
1565
- if (isValidStyleKey(key2, staticConfig)) {
1566
- acc.push({
1567
- type: "style",
1568
- value: {
1569
- [key2]: value2
1570
- },
1571
- name: key2,
1572
- attr: cur.value
1573
- });
1574
- } else {
1575
- acc.push({
1576
- type: "attr",
1577
- value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
1578
- });
1579
- }
1580
- }
1581
- }
1582
- }
1583
- }
1584
- }
1585
- if (cur.type !== "style") {
1586
- acc.push(cur);
1587
- return acc;
1588
- }
1589
- let key = Object.keys(cur.value)[0];
1590
- const value = cur.value[key];
1591
- const fullKey = tamaguiConfig?.shorthands[key];
1592
- if (fullKey) {
1593
- cur.value = {
1594
- [fullKey]: value
1595
- };
1596
- key = fullKey;
1597
- }
1598
- if (disableExtractVariables) {
1599
- if (value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey))) {
1600
- if (shouldPrintDebug) {
1601
- logger.info([` keeping variable inline: ${key} =`, value].join(" "));
1602
- }
1603
- acc.push({
1604
- type: "attr",
1605
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
1606
- });
1607
- return acc;
1608
- }
1609
- }
1610
- acc.push(cur);
1611
- return acc;
1612
- }, []);
1613
- tm.mark("jsx-element-expanded", !!shouldPrintDebug);
1614
- if (shouldPrintDebug) {
1615
- logger.info([" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1616
- }
1617
- let prev = null;
1618
- const getProps = (props, includeProps = false, debugName = "", branchProps) => {
1619
- if (!props) {
1620
- if (shouldPrintDebug) logger.info([" getProps() no props"].join(" "));
1621
- return {};
1622
- }
1623
- if (excludeProps?.size) {
1624
- for (const key in props) {
1625
- if (excludeProps.has(key)) {
1626
- if (shouldPrintDebug) logger.info([" delete excluded", key].join(" "));
1627
- delete props[key];
1628
- }
1629
- }
1630
- }
1631
- const before = process.env.IS_STATIC;
1632
- process.env.IS_STATIC = "is_static";
1633
- try {
1634
- const fallbackProps = branchProps ? {
1635
- ...completeProps,
1636
- ...branchProps
1637
- } : completeProps;
1638
- let extractedMediaLikeProps = null;
1639
- let propsForSplit = props;
1640
- for (const k in props) {
1641
- if (k[0] === "$" && (k.startsWith("$group-") || k.startsWith("$theme-"))) {
1642
- if (propsForSplit === props) {
1643
- propsForSplit = {
1644
- ...props
1645
- };
1646
- }
1647
- if (platform2 === "native" && k.startsWith("$group-") && getGroupPseudo(k) === "hover") {
1648
- delete propsForSplit[k];
1649
- continue;
1650
- }
1651
- extractedMediaLikeProps ||= {};
1652
- extractedMediaLikeProps[k] = propsForSplit[k];
1653
- delete propsForSplit[k];
1654
- }
1655
- }
1656
- const out = getSplitStyles(propsForSplit, staticConfig, defaultTheme, "", componentState, {
1657
- ...styleProps,
1658
- noClass: true,
1659
- fallbackProps,
1660
- ...(platform2 === "native" && {
1661
- resolveValues: "except-theme"
1662
- })
1663
- }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1664
- if (extractedMediaLikeProps && platform2 !== "native") {
1665
- for (const k in extractedMediaLikeProps) {
1666
- const block = extractedMediaLikeProps[k];
1667
- if (!block || typeof block !== "object") continue;
1668
- const blockOut = getSplitStyles(block, staticConfig, defaultTheme, "", componentState, {
1669
- ...styleProps,
1670
- noClass: true,
1671
- fallbackProps
1672
- }, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
1673
- if (blockOut) {
1674
- extractedMediaLikeProps[k] = {
1675
- ...blockOut.style,
1676
- ...blockOut.pseudos
1677
- };
1678
- }
1679
- }
1680
- }
1681
- let outProps = {
1682
- ...(includeProps ? out.viewProps : {}),
1683
- ...out.style,
1684
- ...out.pseudos,
1685
- ...extractedMediaLikeProps
1686
- };
1687
- for (const key in outProps) {
1688
- if (deoptProps.has(key)) {
1689
- shouldFlatten = false;
1690
- }
1691
- if (platform2 === "native" && key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$group-") && getGroupPseudo(key) !== "hover" ||
1692
- // same story for a breakpoint a variant brought with it:
1693
- // native matches media at render time, so there is nothing
1694
- // to write it to here
1695
- mediaQueryConfig[key.slice(1)])) {
1696
- shouldFlatten = false;
1697
- }
1698
- }
1699
- if (shouldPrintDebug) {
1700
- logger.info(`(${debugName})`);
1701
- logger.info(`
1702
- getProps (props in): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props))}`);
1703
- logger.info(`
1704
- getProps (outProps): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outProps))}`);
1705
- }
1706
- if (out.fontFamily) {
1707
- (0, import_propsToFontFamilyCache.setPropsToFontFamily)(outProps, out.fontFamily);
1708
- if (shouldPrintDebug) {
1709
- logger.info(`
1710
- \u{1F4AC} new font fam: ${out.fontFamily}`);
1711
- }
1712
- }
1713
- return outProps;
1714
- } catch (err) {
1715
- logger.info(["error", err.message, err.stack].join(" "));
1716
- return {};
1717
- } finally {
1718
- process.env.IS_STATIC = before;
1719
- }
1720
- };
1721
- attrs.unshift({
1722
- type: "style",
1723
- value: defaultProps
1724
- });
1725
- attrs = attrs.reduce((acc, cur) => {
1726
- if (cur.type === "style") {
1727
- const keys = Object.keys(cur.value || {});
1728
- if (!keys.length) {
1729
- return acc;
1730
- }
1731
- const key = keys[0];
1732
- const value = cur.value[key];
1733
- const isMediaLikeKey = key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$platform-") || key.startsWith("$group-") || mediaQueryConfig[key.slice(1)]);
1734
- const shouldKeepOriginalAttr =
1735
- // !isStyleAndAttr[key] &&
1736
- !shouldFlatten &&
1737
- // de-opt if non-style
1738
- !validStyles[key] && !pseudoDescriptors[key] && !isMediaLikeKey && !(key.startsWith("data-") || key.startsWith("aria-"));
1739
- if (shouldKeepOriginalAttr) {
1740
- if (shouldPrintDebug) {
1741
- logger.info([" - keeping as non-style", key].join(" "));
1742
- }
1743
- prev = cur;
1744
- acc.push({
1745
- type: "attr",
1746
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)))
1747
- });
1748
- acc.push(cur);
1749
- return acc;
1750
- }
1751
- if (prev?.type === "style") {
1752
- mergeStyles(prev.value, cur.value);
1753
- return acc;
1754
- }
1755
- }
1756
- if (cur.type === "style") {
1757
- prev = cur;
1758
- }
1759
- acc.push(cur);
1760
- return acc;
1761
- }, []);
1762
- if (shouldPrintDebug) {
1763
- logger.info([" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1764
- }
1765
- let getStyleError = null;
1766
- const mediaFromVariants = [];
1767
- for (const attr of attrs) {
1768
- try {
1769
- if (shouldPrintDebug) {
1770
- console.info(` Processing ${attr.type}:`);
1771
- }
1772
- switch (attr.type) {
1773
- case "ternary":
1774
- {
1775
- const branchProps = ternaryBranchProps.get((0, import_normalizeTernaries.getTernaryKey)(attr.value.test));
1776
- const a = getProps(attr.value.alternate, false, "ternary.alternate", branchProps?.alternate);
1777
- const c = getProps(attr.value.consequent, false, "ternary.consequent", branchProps?.consequent);
1778
- if (a) attr.value.alternate = a;
1779
- if (c) attr.value.consequent = c;
1780
- if (shouldPrintDebug) logger.info([" => tern ", (0, import_extractHelpers.attrStr)(attr)].join(" "));
1781
- continue;
1782
- }
1783
- case "style":
1784
- {
1785
- const styles = getProps(attr.value, false, "style");
1786
- if (styles) {
1787
- for (const key in styles) {
1788
- if (key[0] !== "$") continue;
1789
- const mediaKey = key.slice(1);
1790
- if (!mediaQueryConfig[mediaKey]) continue;
1791
- mediaFromVariants.push({
1792
- type: "ternary",
1793
- value: {
1794
- inlineMediaQuery: mediaKey,
1795
- test: t.stringLiteral(mediaKey),
1796
- consequent: styles[key],
1797
- alternate: null,
1798
- remove() {}
1799
- }
1800
- });
1801
- delete styles[key];
1802
- }
1803
- attr.value = styles;
1804
- }
1805
- if (shouldPrintDebug) logger.info([" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value))].join(" "));
1806
- if (shouldPrintDebug) logger.info([" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles))].join(" "));
1807
- continue;
1808
- }
1809
- case "attr":
1810
- {
1811
- if (shouldFlatten && t.isJSXAttribute(attr.value)) {
1812
- const key = attr.value.name.name;
1813
- if (key === "style" || key === "className" || key === "render") {
1814
- continue;
1815
- }
1816
- const value = attemptEvalSafe(attr.value.value || t.booleanLiteral(true));
1817
- if (value !== import_constants.FAILED_EVAL) {
1818
- const outProps = getProps({
1819
- [key]: value
1820
- }, true, `attr.${key}`);
1821
- const outKey = Object.keys(outProps)[0];
1822
- if (outKey) {
1823
- const outVal = outProps[outKey];
1824
- attr.value = t.jsxAttribute(t.jsxIdentifier(outKey), t.jsxExpressionContainer(typeof outVal === "string" ? t.stringLiteral(outVal) : (0, import_literalToAst.literalToAst)(outVal)));
1825
- }
1826
- }
1827
- }
1828
- }
1829
- }
1830
- } catch (err) {
1831
- getStyleError = err;
1832
- }
1833
- }
1834
- if (mediaFromVariants.length) {
1835
- attrs.push(...mediaFromVariants);
1836
- }
1837
- if (shouldPrintDebug) {
1838
- logger.info([" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1839
- }
1840
- tm.mark("jsx-element-styles", !!shouldPrintDebug);
1841
- if (getStyleError) {
1842
- logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
1843
- node.attributes = ogAttributes;
1844
- return null;
1845
- }
1846
- const existingStyleKeys = /* @__PURE__ */new Set();
1847
- for (let i = attrs.length - 1; i >= 0; i--) {
1848
- const attr = attrs[i];
1849
- if (shouldFlatten) {
1850
- if (attr.type === "attr") {
1851
- if (t.isJSXAttribute(attr.value)) {
1852
- if (t.isJSXIdentifier(attr.value.name)) {
1853
- const name = attr.value.name.name;
1854
- if (INLINE_EXTRACTABLE[name]) {
1855
- attr.value.name.name = INLINE_EXTRACTABLE[name];
1856
- }
1857
- }
1858
- }
1859
- }
1860
- }
1861
- if (attr.type === "style") {
1862
- for (const key in attr.value) {
1863
- if (existingStyleKeys.has(key)) {
1864
- if (shouldPrintDebug) {
1865
- logger.info([` >> delete existing ${key}`].join(" "));
1866
- }
1867
- delete attr.value[key];
1868
- } else {
1869
- existingStyleKeys.add(key);
1870
- }
1871
- }
1872
- }
1873
- }
1874
- attrs = attrs.filter(Boolean);
1875
- if (!shouldFlatten) {
1876
- if (inlineWhenUnflattened.size) {
1877
- for (const [index, attr] of attrs.entries()) {
1878
- if (attr.type === "style") {
1879
- for (const key in attr.value) {
1880
- if (!inlineWhenUnflattened.has(key)) continue;
1881
- const val = inlineWhenUnflattenedOGVals[key];
1882
- if (val) {
1883
- delete attr.value[key];
1884
- attrs.splice(index - 1, 0, val.attr);
1885
- } else {
1886
- delete attr.value[key];
1887
- }
1888
- }
1889
- }
1890
- }
1891
- }
1892
- }
1893
- attrs = attrs.filter(x => {
1894
- if (x.type === "style" && Object.keys(x.value).length === 0) {
1895
- return false;
1896
- }
1897
- return true;
1898
- });
1899
- const isNativeNotFlat = !shouldFlatten && platform2 === "native";
1900
- if (isNativeNotFlat) {
1901
- if (shouldPrintDebug) {
1902
- logger.info(`Disabled flattening except for simple cases on native for now: ${JSON.stringify({
1903
- flatNode: flatNodeName,
1904
- shouldDeopt,
1905
- canFlattenProps,
1906
- hasSpread,
1907
- "staticConfig.isStyledHOC": staticConfig.isStyledHOC,
1908
- "!staticConfig.isHOC": !staticConfig.isHOC,
1909
- "staticConfig.isReactNative": staticConfig.isReactNative,
1910
- "staticConfig.neverFlatten": staticConfig.neverFlatten
1911
- }, null, 2)}`);
1912
- }
1913
- node.attributes = ogAttributes;
1914
- return null;
1915
- }
1916
- if (shouldPrintDebug) {
1917
- logger.info([` - inlined props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
1918
- logger.info(` - attrs (end):
1919
- ${(0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))}`);
1920
- }
1921
- onExtractTag({
1922
- parserProps: propsWithFileInfo,
1923
- attrs,
1924
- node,
1925
- lineNumbers,
1926
- filePath,
1927
- config: tamaguiConfig,
1928
- flatNodeName,
1929
- attemptEval,
1930
- jsxPath: traversePath,
1931
- originalNodeName,
1932
- programPath,
1933
- completeProps,
1934
- staticConfig
1935
- });
1936
- if (shouldFlatten) {
1937
- if (shouldPrintDebug) {
1938
- logger.info([" [\u2705] flattened", originalNodeName, flatNodeName].join(" "));
1939
- }
1940
- const currentName = node.name?.name;
1941
- if (!currentName || currentName === originalNodeName || currentName.startsWith("__ReactNative")) {
1942
- node.name.name = flatNodeName;
1943
- if (closingElement) {
1944
- closingElement.name.name = flatNodeName;
1945
- }
1946
- }
1947
- res.flattened++;
1948
- }
1949
- } catch (err) {
1950
- node.attributes = ogAttributes;
1951
- if (!(err instanceof import_errors.BailOptimizationError)) {
1952
- console.error(`@tamagui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment TAMAGUI_DEBUG=1`);
1953
- if (process.env.TAMAGUI_DEBUG === "1") {
1954
- console.error(err.stack);
1955
- }
1956
- }
1957
- } finally {
1958
- if (debugPropValue) {
1959
- shouldPrintDebug = ogDebug;
1960
- }
1961
- }
1962
- }
1963
- });
1964
- tm.mark("jsx-done", !!shouldPrintDebug);
1965
- tm.done(shouldPrintDebug === "verbose");
1966
- return res;
1967
- }
1968
- }