@tamagui/static 1.0.1-beta.99 → 1.0.1-rc.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/{cjs/constants.js → constants.js} +9 -4
  2. package/dist/constants.js.map +7 -0
  3. package/dist/{cjs/extractor → extractor}/accessSafe.js +14 -2
  4. package/dist/{esm/extractor → extractor}/accessSafe.js.map +2 -2
  5. package/dist/{cjs/extractor → extractor}/babelParse.js +5 -1
  6. package/dist/extractor/babelParse.js.map +7 -0
  7. package/dist/{cjs/extractor → extractor}/buildClassName.js +40 -9
  8. package/dist/extractor/buildClassName.js.map +7 -0
  9. package/dist/extractor/bundle.js +117 -0
  10. package/dist/extractor/bundle.js.map +7 -0
  11. package/dist/{cjs/extractor → extractor}/createEvaluator.js +11 -8
  12. package/dist/extractor/createEvaluator.js.map +7 -0
  13. package/dist/extractor/createExtractor.js +1623 -0
  14. package/dist/extractor/createExtractor.js.map +7 -0
  15. package/dist/{cjs/extractor → extractor}/ensureImportingConcat.js +18 -6
  16. package/dist/extractor/ensureImportingConcat.js.map +7 -0
  17. package/dist/{cjs/extractor → extractor}/evaluateAstNode.js +14 -4
  18. package/dist/extractor/evaluateAstNode.js.map +7 -0
  19. package/dist/{cjs/extractor → extractor}/extractHelpers.js +83 -12
  20. package/dist/extractor/extractHelpers.js.map +7 -0
  21. package/dist/{cjs/extractor → extractor}/extractMediaStyle.js +46 -42
  22. package/dist/extractor/extractMediaStyle.js.map +7 -0
  23. package/dist/{cjs/extractor → extractor}/extractToClassNames.js +144 -73
  24. package/dist/extractor/extractToClassNames.js.map +7 -0
  25. package/dist/{cjs/extractor → extractor}/findTopmostFunction.js +1 -0
  26. package/dist/{cjs/extractor → extractor}/findTopmostFunction.js.map +2 -2
  27. package/dist/{cjs/extractor → extractor}/generatedUid.js +9 -2
  28. package/dist/{cjs/extractor → extractor}/generatedUid.js.map +3 -3
  29. package/dist/{cjs/extractor → extractor}/getPrefixLogs.js +1 -0
  30. package/dist/extractor/getPrefixLogs.js.map +7 -0
  31. package/dist/{cjs/extractor → extractor}/getPropValueFromAttributes.js +24 -13
  32. package/dist/extractor/getPropValueFromAttributes.js.map +7 -0
  33. package/dist/{cjs/extractor → extractor}/getSourceModule.js +5 -1
  34. package/dist/{esm/extractor → extractor}/getSourceModule.js.map +3 -3
  35. package/dist/{cjs/extractor → extractor}/getStaticBindingsForScope.js +89 -35
  36. package/dist/extractor/getStaticBindingsForScope.js.map +7 -0
  37. package/dist/{cjs/extractor → extractor}/hoistClassNames.js +5 -1
  38. package/dist/{jsx/extractor → extractor}/hoistClassNames.js.map +3 -3
  39. package/dist/{cjs/extractor → extractor}/literalToAst.js +26 -30
  40. package/dist/{jsx/extractor → extractor}/literalToAst.js.map +2 -2
  41. package/dist/extractor/loadFile.js +21 -0
  42. package/dist/extractor/loadFile.js.map +7 -0
  43. package/dist/extractor/loadTamagui.js +427 -0
  44. package/dist/extractor/loadTamagui.js.map +7 -0
  45. package/dist/{cjs/extractor → extractor}/logLines.js +2 -1
  46. package/dist/extractor/logLines.js.map +7 -0
  47. package/dist/{cjs/extractor → extractor}/normalizeTernaries.js +13 -34
  48. package/dist/extractor/normalizeTernaries.js.map +7 -0
  49. package/dist/{cjs/extractor → extractor}/removeUnusedHooks.js +5 -1
  50. package/dist/extractor/removeUnusedHooks.js.map +7 -0
  51. package/dist/{cjs/extractor → extractor}/timer.js +9 -1
  52. package/dist/extractor/timer.js.map +7 -0
  53. package/dist/{cjs/extractor → extractor}/validHTMLAttributes.js +1 -0
  54. package/dist/{jsx/extractor → extractor}/validHTMLAttributes.js.map +2 -2
  55. package/dist/getPragmaOptions.js +68 -0
  56. package/dist/getPragmaOptions.js.map +7 -0
  57. package/dist/helpers/memoize.js +46 -0
  58. package/dist/helpers/memoize.js.map +7 -0
  59. package/dist/{cjs/index.js → index.js} +10 -8
  60. package/dist/index.js.map +7 -0
  61. package/dist/require.js +86 -0
  62. package/dist/require.js.map +7 -0
  63. package/dist/{cjs/types.js → types.js} +1 -0
  64. package/dist/types.js.map +7 -0
  65. package/dist/webpackPlugin.js +35 -0
  66. package/dist/webpackPlugin.js.map +7 -0
  67. package/package.json +40 -36
  68. package/src/constants.ts +2 -1
  69. package/src/extractor/babelParse.ts +3 -2
  70. package/src/extractor/buildClassName.ts +21 -5
  71. package/src/extractor/bundle.ts +110 -0
  72. package/src/extractor/createEvaluator.ts +10 -12
  73. package/src/extractor/createExtractor.ts +1702 -1523
  74. package/src/extractor/ensureImportingConcat.ts +4 -11
  75. package/src/extractor/evaluateAstNode.ts +1 -1
  76. package/src/extractor/extractHelpers.ts +93 -10
  77. package/src/extractor/extractMediaStyle.ts +18 -11
  78. package/src/extractor/extractToClassNames.ts +104 -47
  79. package/src/extractor/getPrefixLogs.ts +1 -1
  80. package/src/extractor/getPropValueFromAttributes.ts +4 -3
  81. package/src/extractor/getSourceModule.ts +2 -0
  82. package/src/extractor/getStaticBindingsForScope.ts +90 -46
  83. package/src/extractor/loadFile.ts +17 -0
  84. package/src/extractor/loadTamagui.ts +448 -103
  85. package/src/extractor/logLines.ts +1 -1
  86. package/src/extractor/normalizeTernaries.ts +2 -2
  87. package/src/extractor/removeUnusedHooks.ts +2 -0
  88. package/src/extractor/timer.ts +12 -1
  89. package/src/getPragmaOptions.ts +53 -0
  90. package/src/helpers/memoize.ts +21 -0
  91. package/src/index.ts +9 -8
  92. package/src/require.ts +103 -0
  93. package/src/types.ts +33 -31
  94. package/src/webpackPlugin.ts +9 -0
  95. package/tamagui.tsconfig.json +5 -0
  96. package/types/constants.d.ts +6 -0
  97. package/types/extractor/accessSafe.d.ts +3 -0
  98. package/types/extractor/babelParse.d.ts +6 -0
  99. package/types/extractor/buildClassName.d.ts +5 -2
  100. package/types/extractor/bundle.d.ts +13 -0
  101. package/types/extractor/createEvaluator.d.ts +3 -3
  102. package/types/extractor/createExtractor.d.ts +25 -9
  103. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  104. package/types/extractor/evaluateAstNode.d.ts +3 -0
  105. package/types/extractor/extractHelpers.d.ts +15 -3
  106. package/types/extractor/extractMediaStyle.d.ts +3 -3
  107. package/types/extractor/extractToClassNames.d.ts +5 -4
  108. package/types/extractor/findTopmostFunction.d.ts +4 -0
  109. package/types/extractor/generatedUid.d.ts +5 -0
  110. package/types/extractor/getPrefixLogs.d.ts +1 -1
  111. package/types/extractor/getPropValueFromAttributes.d.ts +19 -0
  112. package/types/extractor/getSourceModule.d.ts +16 -0
  113. package/types/extractor/getStaticBindingsForScope.d.ts +5 -0
  114. package/types/extractor/hoistClassNames.d.ts +6 -0
  115. package/types/extractor/literalToAst.d.ts +4 -0
  116. package/types/extractor/loadFile.d.ts +1 -0
  117. package/types/extractor/loadTamagui.d.ts +15 -5
  118. package/types/extractor/logLines.d.ts +2 -0
  119. package/types/extractor/normalizeTernaries.d.ts +1 -1
  120. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  121. package/types/extractor/timer.d.ts +5 -0
  122. package/types/extractor/validHTMLAttributes.d.ts +98 -0
  123. package/types/getPragmaOptions.d.ts +9 -0
  124. package/types/helpers/memoize.d.ts +8 -0
  125. package/types/index.d.ts +9 -8
  126. package/types/require.d.ts +4 -0
  127. package/types/types.d.ts +28 -27
  128. package/types/webpackPlugin.d.ts +4 -0
  129. package/dist/cjs/constants.js.map +0 -7
  130. package/dist/cjs/extractor/accessSafe.js.map +0 -7
  131. package/dist/cjs/extractor/babelParse.js.map +0 -7
  132. package/dist/cjs/extractor/buildClassName.js.map +0 -7
  133. package/dist/cjs/extractor/createEvaluator.js.map +0 -7
  134. package/dist/cjs/extractor/createExtractor.js +0 -1394
  135. package/dist/cjs/extractor/createExtractor.js.map +0 -7
  136. package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -7
  137. package/dist/cjs/extractor/evaluateAstNode.js.map +0 -7
  138. package/dist/cjs/extractor/extractHelpers.js.map +0 -7
  139. package/dist/cjs/extractor/extractMediaStyle.js.map +0 -7
  140. package/dist/cjs/extractor/extractToClassNames.js.map +0 -7
  141. package/dist/cjs/extractor/getPrefixLogs.js.map +0 -7
  142. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -7
  143. package/dist/cjs/extractor/getSourceModule.js.map +0 -7
  144. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +0 -7
  145. package/dist/cjs/extractor/hoistClassNames.js.map +0 -7
  146. package/dist/cjs/extractor/literalToAst.js.map +0 -7
  147. package/dist/cjs/extractor/loadTamagui.js +0 -139
  148. package/dist/cjs/extractor/loadTamagui.js.map +0 -7
  149. package/dist/cjs/extractor/logLines.js.map +0 -7
  150. package/dist/cjs/extractor/normalizeTernaries.js.map +0 -7
  151. package/dist/cjs/extractor/removeUnusedHooks.js.map +0 -7
  152. package/dist/cjs/extractor/timer.js.map +0 -7
  153. package/dist/cjs/extractor/validHTMLAttributes.js.map +0 -7
  154. package/dist/cjs/index.js.map +0 -7
  155. package/dist/cjs/types.js.map +0 -7
  156. package/dist/esm/constants.js +0 -14
  157. package/dist/esm/constants.js.map +0 -7
  158. package/dist/esm/extractor/accessSafe.js +0 -8
  159. package/dist/esm/extractor/babelParse.js +0 -28
  160. package/dist/esm/extractor/babelParse.js.map +0 -7
  161. package/dist/esm/extractor/buildClassName.js +0 -37
  162. package/dist/esm/extractor/buildClassName.js.map +0 -7
  163. package/dist/esm/extractor/createEvaluator.js +0 -53
  164. package/dist/esm/extractor/createEvaluator.js.map +0 -7
  165. package/dist/esm/extractor/createExtractor.js +0 -1379
  166. package/dist/esm/extractor/createExtractor.js.map +0 -7
  167. package/dist/esm/extractor/ensureImportingConcat.js +0 -21
  168. package/dist/esm/extractor/ensureImportingConcat.js.map +0 -7
  169. package/dist/esm/extractor/evaluateAstNode.js +0 -91
  170. package/dist/esm/extractor/evaluateAstNode.js.map +0 -7
  171. package/dist/esm/extractor/extractHelpers.js +0 -97
  172. package/dist/esm/extractor/extractHelpers.js.map +0 -7
  173. package/dist/esm/extractor/extractMediaStyle.js +0 -161
  174. package/dist/esm/extractor/extractMediaStyle.js.map +0 -7
  175. package/dist/esm/extractor/extractToClassNames.js +0 -294
  176. package/dist/esm/extractor/extractToClassNames.js.map +0 -7
  177. package/dist/esm/extractor/findTopmostFunction.js +0 -20
  178. package/dist/esm/extractor/findTopmostFunction.js.map +0 -7
  179. package/dist/esm/extractor/generatedUid.js +0 -25
  180. package/dist/esm/extractor/generatedUid.js.map +0 -7
  181. package/dist/esm/extractor/getPrefixLogs.js +0 -8
  182. package/dist/esm/extractor/getPrefixLogs.js.map +0 -7
  183. package/dist/esm/extractor/getPropValueFromAttributes.js +0 -46
  184. package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -7
  185. package/dist/esm/extractor/getSourceModule.js +0 -66
  186. package/dist/esm/extractor/getStaticBindingsForScope.js +0 -132
  187. package/dist/esm/extractor/getStaticBindingsForScope.js.map +0 -7
  188. package/dist/esm/extractor/hoistClassNames.js +0 -40
  189. package/dist/esm/extractor/hoistClassNames.js.map +0 -7
  190. package/dist/esm/extractor/literalToAst.js +0 -90
  191. package/dist/esm/extractor/literalToAst.js.map +0 -7
  192. package/dist/esm/extractor/loadTamagui.js +0 -117
  193. package/dist/esm/extractor/loadTamagui.js.map +0 -7
  194. package/dist/esm/extractor/logLines.js +0 -20
  195. package/dist/esm/extractor/logLines.js.map +0 -7
  196. package/dist/esm/extractor/normalizeTernaries.js +0 -79
  197. package/dist/esm/extractor/normalizeTernaries.js.map +0 -7
  198. package/dist/esm/extractor/removeUnusedHooks.js +0 -76
  199. package/dist/esm/extractor/removeUnusedHooks.js.map +0 -7
  200. package/dist/esm/extractor/timer.js +0 -22
  201. package/dist/esm/extractor/timer.js.map +0 -7
  202. package/dist/esm/extractor/validHTMLAttributes.js +0 -102
  203. package/dist/esm/extractor/validHTMLAttributes.js.map +0 -7
  204. package/dist/esm/index.js +0 -15
  205. package/dist/esm/index.js.map +0 -7
  206. package/dist/esm/types.js +0 -1
  207. package/dist/esm/types.js.map +0 -7
  208. package/dist/jsx/constants.js +0 -14
  209. package/dist/jsx/constants.js.map +0 -7
  210. package/dist/jsx/extractor/accessSafe.js +0 -8
  211. package/dist/jsx/extractor/accessSafe.js.map +0 -7
  212. package/dist/jsx/extractor/babelParse.js +0 -28
  213. package/dist/jsx/extractor/babelParse.js.map +0 -7
  214. package/dist/jsx/extractor/buildClassName.js +0 -37
  215. package/dist/jsx/extractor/buildClassName.js.map +0 -7
  216. package/dist/jsx/extractor/createEvaluator.js +0 -53
  217. package/dist/jsx/extractor/createEvaluator.js.map +0 -7
  218. package/dist/jsx/extractor/createExtractor.js +0 -1343
  219. package/dist/jsx/extractor/createExtractor.js.map +0 -7
  220. package/dist/jsx/extractor/ensureImportingConcat.js +0 -21
  221. package/dist/jsx/extractor/ensureImportingConcat.js.map +0 -7
  222. package/dist/jsx/extractor/evaluateAstNode.js +0 -91
  223. package/dist/jsx/extractor/evaluateAstNode.js.map +0 -7
  224. package/dist/jsx/extractor/extractHelpers.js +0 -97
  225. package/dist/jsx/extractor/extractHelpers.js.map +0 -7
  226. package/dist/jsx/extractor/extractMediaStyle.js +0 -146
  227. package/dist/jsx/extractor/extractMediaStyle.js.map +0 -7
  228. package/dist/jsx/extractor/extractToClassNames.js +0 -280
  229. package/dist/jsx/extractor/extractToClassNames.js.map +0 -7
  230. package/dist/jsx/extractor/findTopmostFunction.js +0 -20
  231. package/dist/jsx/extractor/findTopmostFunction.js.map +0 -7
  232. package/dist/jsx/extractor/generatedUid.js +0 -25
  233. package/dist/jsx/extractor/generatedUid.js.map +0 -7
  234. package/dist/jsx/extractor/getPrefixLogs.js +0 -9
  235. package/dist/jsx/extractor/getPrefixLogs.js.map +0 -7
  236. package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -46
  237. package/dist/jsx/extractor/getPropValueFromAttributes.js.map +0 -7
  238. package/dist/jsx/extractor/getSourceModule.js +0 -66
  239. package/dist/jsx/extractor/getSourceModule.js.map +0 -7
  240. package/dist/jsx/extractor/getStaticBindingsForScope.js +0 -132
  241. package/dist/jsx/extractor/getStaticBindingsForScope.js.map +0 -7
  242. package/dist/jsx/extractor/hoistClassNames.js +0 -40
  243. package/dist/jsx/extractor/literalToAst.js +0 -75
  244. package/dist/jsx/extractor/loadTamagui.js +0 -102
  245. package/dist/jsx/extractor/loadTamagui.js.map +0 -7
  246. package/dist/jsx/extractor/logLines.js +0 -20
  247. package/dist/jsx/extractor/logLines.js.map +0 -7
  248. package/dist/jsx/extractor/normalizeTernaries.js +0 -50
  249. package/dist/jsx/extractor/normalizeTernaries.js.map +0 -7
  250. package/dist/jsx/extractor/removeUnusedHooks.js +0 -77
  251. package/dist/jsx/extractor/removeUnusedHooks.js.map +0 -7
  252. package/dist/jsx/extractor/timer.js +0 -22
  253. package/dist/jsx/extractor/timer.js.map +0 -7
  254. package/dist/jsx/extractor/validHTMLAttributes.js +0 -102
  255. package/dist/jsx/index.js +0 -15
  256. package/dist/jsx/index.js.map +0 -7
  257. package/dist/jsx/types.js +0 -1
  258. package/dist/jsx/types.js.map +0 -7
  259. package/types/extractor/buildClassName.d.ts.map +0 -1
  260. package/types/extractor/createEvaluator.d.ts.map +0 -1
  261. package/types/extractor/createExtractor.d.ts.map +0 -1
  262. package/types/extractor/extractHelpers.d.ts.map +0 -1
  263. package/types/extractor/extractMediaStyle.d.ts.map +0 -1
  264. package/types/extractor/extractToClassNames.d.ts.map +0 -1
  265. package/types/extractor/getPrefixLogs.d.ts.map +0 -1
  266. package/types/extractor/loadTamagui.d.ts.map +0 -1
  267. package/types/extractor/normalizeTernaries.d.ts.map +0 -1
  268. package/types/index.d.ts.map +0 -1
  269. package/types/types.d.ts.map +0 -1
@@ -0,0 +1,1623 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var createExtractor_exports = {};
26
+ __export(createExtractor_exports, {
27
+ createExtractor: () => createExtractor
28
+ });
29
+ module.exports = __toCommonJS(createExtractor_exports);
30
+ var import_path = require("path");
31
+ var import_traverse = __toESM(require("@babel/traverse"));
32
+ var t = __toESM(require("@babel/types"));
33
+ var import_core_node = require("@tamagui/core-node");
34
+ var import_react_native_web_internals = require("react-native-web-internals");
35
+ var import_constants = require("../constants.js");
36
+ var import_createEvaluator = require("./createEvaluator.js");
37
+ var import_evaluateAstNode = require("./evaluateAstNode.js");
38
+ var import_extractHelpers = require("./extractHelpers.js");
39
+ var import_findTopmostFunction = require("./findTopmostFunction.js");
40
+ var import_getPrefixLogs = require("./getPrefixLogs.js");
41
+ var import_getStaticBindingsForScope = require("./getStaticBindingsForScope.js");
42
+ var import_literalToAst = require("./literalToAst.js");
43
+ var import_loadTamagui = require("./loadTamagui.js");
44
+ var import_logLines = require("./logLines.js");
45
+ var import_normalizeTernaries = require("./normalizeTernaries.js");
46
+ var import_removeUnusedHooks = require("./removeUnusedHooks.js");
47
+ var import_timer = require("./timer.js");
48
+ var import_validHTMLAttributes = require("./validHTMLAttributes.js");
49
+ const UNTOUCHED_PROPS = {
50
+ key: true,
51
+ style: true,
52
+ className: true
53
+ };
54
+ const INLINE_EXTRACTABLE = {
55
+ ref: "ref",
56
+ key: "key",
57
+ ...process.env.TAMAGUI_TARGET === "web" && {
58
+ onPress: "onClick",
59
+ onHoverIn: "onMouseEnter",
60
+ onHoverOut: "onMouseLeave",
61
+ onPressIn: "onMouseDown",
62
+ onPressOut: "onMouseUp"
63
+ }
64
+ };
65
+ const validHooks = {
66
+ useMedia: true,
67
+ useTheme: true
68
+ };
69
+ const isAttr = (x) => x.type === "attr";
70
+ const createTernary = (x) => x;
71
+ let hasLoggedBaseInfo = false;
72
+ function createExtractor({ logger = console } = { logger: console }) {
73
+ if (!process.env.TAMAGUI_TARGET) {
74
+ console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
75
+ process.exit(1);
76
+ }
77
+ const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
78
+ let projectInfo = null;
79
+ function loadSync(props) {
80
+ return projectInfo || (projectInfo = (0, import_loadTamagui.loadTamaguiSync)({
81
+ config: props.config || "tamagui.config.ts",
82
+ components: props.components || ["tamagui"]
83
+ }));
84
+ }
85
+ async function load(props) {
86
+ return projectInfo || (projectInfo = await (0, import_loadTamagui.loadTamagui)({
87
+ config: props.config || "tamagui.config.ts",
88
+ components: props.components || ["tamagui"]
89
+ }));
90
+ }
91
+ return {
92
+ options: {
93
+ logger
94
+ },
95
+ cleanupBeforeExit: import_getStaticBindingsForScope.cleanupBeforeExit,
96
+ loadTamagui: load,
97
+ loadTamaguiSync: loadSync,
98
+ getTamagui() {
99
+ return projectInfo == null ? void 0 : projectInfo.tamaguiConfig;
100
+ },
101
+ parseSync: (f, props) => {
102
+ const projectInfo2 = loadSync(props);
103
+ return parseWithConfig(projectInfo2, f, props);
104
+ },
105
+ parse: async (f, props) => {
106
+ const projectInfo2 = await load(props);
107
+ return parseWithConfig(projectInfo2, f, props);
108
+ }
109
+ };
110
+ function parseWithConfig({ components, tamaguiConfig }, fileOrPath, options) {
111
+ var _a;
112
+ const {
113
+ config = "tamagui.config.ts",
114
+ importsWhitelist = ["constants.js"],
115
+ evaluateVars = true,
116
+ sourcePath = "",
117
+ onExtractTag,
118
+ onStyleRule,
119
+ getFlattenedNode,
120
+ disable,
121
+ disableExtraction,
122
+ disableExtractInlineMedia,
123
+ disableExtractVariables,
124
+ disableDebugAttr,
125
+ disableExtractFoundComponents,
126
+ includeExtensions = [".tsx", ".jsx", ".js"],
127
+ extractStyledDefinitions = false,
128
+ prefixLogs,
129
+ excludeProps,
130
+ target,
131
+ ...restProps
132
+ } = options;
133
+ let shouldPrintDebug = options.shouldPrintDebug || false;
134
+ if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
135
+ return null;
136
+ }
137
+ if (sourcePath === "") {
138
+ throw new Error(`Must provide a source file name`);
139
+ }
140
+ if (!components) {
141
+ throw new Error(`Must provide components`);
142
+ }
143
+ if (includeExtensions && !includeExtensions.some((ext) => sourcePath.endsWith(ext))) {
144
+ if (shouldPrintDebug) {
145
+ logger.info(
146
+ `Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(
147
+ ", "
148
+ )}`
149
+ );
150
+ }
151
+ return null;
152
+ }
153
+ function isValidStyleKey(name, staticConfig) {
154
+ var _a2, _b;
155
+ if (!projectInfo) {
156
+ throw new Error(`Tamagui extractor not loaded yet`);
157
+ }
158
+ if (target === "native" && name[0] === "$" && import_core_node.mediaQueryConfig[name.slice(1)]) {
159
+ return false;
160
+ }
161
+ return !!(!!((_a2 = staticConfig.validStyles) == null ? void 0 : _a2[name]) || !!import_core_node.pseudoDescriptors[name] || ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || (projectInfo == null ? void 0 : projectInfo.tamaguiConfig.shorthands[name]) || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
162
+ }
163
+ const isTargetingHTML = target === "html";
164
+ const ogDebug = shouldPrintDebug;
165
+ const tm = (0, import_timer.timer)();
166
+ const propsWithFileInfo = {
167
+ ...options,
168
+ sourcePath,
169
+ allLoadedComponents: [...components]
170
+ };
171
+ if (!hasLoggedBaseInfo) {
172
+ hasLoggedBaseInfo = true;
173
+ if (shouldPrintDebug) {
174
+ logger.info(
175
+ [
176
+ "loaded components:",
177
+ propsWithFileInfo.allLoadedComponents.map((comp) => Object.keys(comp.nameToInfo).join(", ")).join(", ")
178
+ ].join(" ")
179
+ );
180
+ }
181
+ if ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui")) {
182
+ const next = [...propsWithFileInfo.allLoadedComponents].map((info) => {
183
+ const nameToInfo = { ...info.nameToInfo };
184
+ for (const key in nameToInfo) {
185
+ delete nameToInfo[key].staticConfig.validStyles;
186
+ }
187
+ return { ...info, nameToInfo };
188
+ });
189
+ logger.info(["loaded:", JSON.stringify(next, null, 2)].join("\n"));
190
+ }
191
+ }
192
+ tm.mark("load-tamagui", !!shouldPrintDebug);
193
+ const firstThemeName = Object.keys(tamaguiConfig.themes)[0];
194
+ const firstTheme = tamaguiConfig.themes[firstThemeName];
195
+ if (!firstTheme || typeof firstTheme !== "object") {
196
+ console.error(`Missing theme, an error occurred when importing your config`);
197
+ console.log(`Got config:`, tamaguiConfig);
198
+ console.log(`Looking for theme:`, firstThemeName);
199
+ process.exit(0);
200
+ }
201
+ const proxiedTheme = (0, import_core_node.proxyThemeVariables)(firstTheme);
202
+ const themeAccessListeners = /* @__PURE__ */ new Set();
203
+ const defaultTheme = new Proxy(proxiedTheme, {
204
+ get(target2, key) {
205
+ if (Reflect.has(target2, key)) {
206
+ themeAccessListeners.forEach((cb) => cb(String(key)));
207
+ }
208
+ return Reflect.get(target2, key);
209
+ }
210
+ });
211
+ const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
212
+ if (Object.keys(components).length === 0) {
213
+ console.warn(`Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)`);
214
+ if (process.env.DEBUG === "tamagui") {
215
+ console.log(`components`, Object.keys(components), components);
216
+ }
217
+ }
218
+ if (shouldPrintDebug === "verbose") {
219
+ logger.info(
220
+ `allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map((k) => k.moduleName).join(", ")}`
221
+ );
222
+ }
223
+ let doesUseValidImport = false;
224
+ let hasImportedTheme = false;
225
+ const importDeclarations = [];
226
+ for (const bodyPath of body) {
227
+ if (bodyPath.type !== "ImportDeclaration")
228
+ continue;
229
+ const node = "node" in bodyPath ? bodyPath.node : bodyPath;
230
+ const moduleName = node.source.value;
231
+ const valid = (0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName);
232
+ if (valid) {
233
+ importDeclarations.push(node);
234
+ }
235
+ if (extractStyledDefinitions) {
236
+ if (valid) {
237
+ if (node.specifiers.some((specifier) => specifier.local.name === "styled")) {
238
+ doesUseValidImport = true;
239
+ break;
240
+ }
241
+ }
242
+ }
243
+ if (valid) {
244
+ const names = node.specifiers.map((specifier) => specifier.local.name);
245
+ const isValidComponent = names.some(
246
+ (name) => Boolean((0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, name) || validHooks[name])
247
+ );
248
+ if (shouldPrintDebug === "verbose") {
249
+ logger.info(
250
+ `import ${names.join(", ")} from ${moduleName} isValidComponent ${isValidComponent}`
251
+ );
252
+ }
253
+ if (isValidComponent) {
254
+ doesUseValidImport = true;
255
+ break;
256
+ }
257
+ }
258
+ }
259
+ if (shouldPrintDebug) {
260
+ logger.info(`file: ${sourcePath} ${JSON.stringify({ doesUseValidImport, hasImportedTheme })}`);
261
+ }
262
+ if (!doesUseValidImport) {
263
+ return null;
264
+ }
265
+ function getValidImportedComponent(componentName) {
266
+ const importDeclaration = importDeclarations.find(
267
+ (dec) => dec.specifiers.some((spec) => spec.local.name === componentName)
268
+ );
269
+ if (!importDeclaration) {
270
+ return null;
271
+ }
272
+ return (0, import_extractHelpers.getValidImport)(propsWithFileInfo, importDeclaration.source.value, componentName);
273
+ }
274
+ tm.mark("import-check", !!shouldPrintDebug);
275
+ let couldntParse = false;
276
+ const modifiedComponents = /* @__PURE__ */ new Set();
277
+ const bindingCache = {};
278
+ const callTraverse = (a) => {
279
+ return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
280
+ };
281
+ const shouldDisableExtraction = disableExtraction === true || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
282
+ let programPath = null;
283
+ const res = {
284
+ styled: 0,
285
+ flattened: 0,
286
+ optimized: 0,
287
+ modified: 0,
288
+ found: 0
289
+ };
290
+ callTraverse({
291
+ Program: {
292
+ enter(path) {
293
+ programPath = path;
294
+ }
295
+ },
296
+ CallExpression(path) {
297
+ var _a2;
298
+ if (disable || shouldDisableExtraction || extractStyledDefinitions === false) {
299
+ return;
300
+ }
301
+ if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
302
+ return;
303
+ }
304
+ const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
305
+ const definition = path.node.arguments[1];
306
+ if (!name || !definition || !t.isObjectExpression(definition)) {
307
+ return;
308
+ }
309
+ let Component = getValidImportedComponent(name);
310
+ if (!Component) {
311
+ if (disableExtractFoundComponents === true) {
312
+ return;
313
+ }
314
+ if (Array.isArray(disableExtractFoundComponents) && disableExtractFoundComponents.includes(name)) {
315
+ return;
316
+ }
317
+ try {
318
+ if (shouldPrintDebug) {
319
+ logger.info(`Unknown component ${name}, attempting dynamic load: ${sourcePath}`);
320
+ }
321
+ const out2 = (0, import_loadTamagui.loadTamaguiSync)({
322
+ forceExports: true,
323
+ components: [sourcePath]
324
+ });
325
+ if (!(out2 == null ? void 0 : out2.components)) {
326
+ if (shouldPrintDebug) {
327
+ logger.info(`Couldn't load, got ${out2}`);
328
+ }
329
+ return;
330
+ }
331
+ propsWithFileInfo.allLoadedComponents = [
332
+ ...propsWithFileInfo.allLoadedComponents,
333
+ ...out2.components
334
+ ];
335
+ Component = out2.components.flatMap((x) => x.nameToInfo[name] ?? [])[0];
336
+ if (shouldPrintDebug === "verbose") {
337
+ logger.info([`Tamagui Loaded`, JSON.stringify(out2.components), !!Component].join(" "));
338
+ }
339
+ } catch (err) {
340
+ if (shouldPrintDebug) {
341
+ logger.info(
342
+ `${(0, import_getPrefixLogs.getPrefixLogs)(
343
+ options
344
+ )} skip optimize styled(${name}), unable to pre-process (DEBUG=tamagui for more)`
345
+ );
346
+ }
347
+ if (process.env.DEBUG === "tamagui") {
348
+ logger.info(
349
+ ` Disable this with "disableExtractFoundComponents" in your build-time configuration.
350
+
351
+ ${err.message} ${err.stack}`
352
+ );
353
+ }
354
+ }
355
+ }
356
+ if (!Component) {
357
+ return;
358
+ }
359
+ const componentSkipProps = /* @__PURE__ */ new Set([
360
+ ...Component.staticConfig.inlineWhenUnflattened || [],
361
+ ...Component.staticConfig.inlineProps || [],
362
+ ...Component.staticConfig.deoptProps || [],
363
+ "variants",
364
+ "defaultVariants",
365
+ "fontFamily",
366
+ "name"
367
+ ]);
368
+ const skipped = [];
369
+ const styles = {};
370
+ const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(
371
+ path.scope,
372
+ importsWhitelist,
373
+ sourcePath,
374
+ bindingCache,
375
+ shouldPrintDebug
376
+ );
377
+ const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
378
+ props: propsWithFileInfo,
379
+ staticNamespace,
380
+ sourcePath,
381
+ shouldPrintDebug
382
+ });
383
+ const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
384
+ for (const property of definition.properties) {
385
+ if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || ((_a2 = Component.staticConfig.variants) == null ? void 0 : _a2[property.key.name]) || componentSkipProps.has(property.key.name)) {
386
+ skipped.push(property);
387
+ continue;
388
+ }
389
+ const out2 = attemptEvalSafe(property.value);
390
+ if (out2 === import_constants.FAILED_EVAL) {
391
+ skipped.push(property);
392
+ } else {
393
+ styles[property.key.name] = out2;
394
+ }
395
+ }
396
+ const out = (0, import_core_node.getSplitStyles)(styles, Component.staticConfig, defaultTheme, {
397
+ focus: false,
398
+ hover: false,
399
+ unmounted: true,
400
+ press: false,
401
+ pressIn: false,
402
+ resolveVariablesAs: "variable",
403
+ noClassNames: false
404
+ });
405
+ const classNames = {
406
+ ...out.classNames
407
+ };
408
+ if (shouldPrintDebug) {
409
+ logger.info([`Extracted styled(${name})
410
+ `, JSON.stringify(styles, null, 2), "\n rulesToInsert:", out.rulesToInsert.flatMap((rule) => rule.rules).join("\n")].join(" "));
411
+ }
412
+ definition.properties = skipped;
413
+ for (const cn in classNames) {
414
+ if (componentSkipProps.has(cn)) {
415
+ continue;
416
+ }
417
+ const val = classNames[cn];
418
+ definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
419
+ }
420
+ if (out.rulesToInsert) {
421
+ for (const { identifier, rules } of out.rulesToInsert) {
422
+ onStyleRule == null ? void 0 : onStyleRule(identifier, rules);
423
+ }
424
+ }
425
+ res.styled++;
426
+ if (shouldPrintDebug) {
427
+ logger.info(`Extracted styled(${name})`);
428
+ }
429
+ },
430
+ JSXElement(traversePath) {
431
+ var _a2;
432
+ if (shouldDisableExtraction) {
433
+ return;
434
+ }
435
+ tm.mark("jsx-element", !!shouldPrintDebug);
436
+ const node = traversePath.node.openingElement;
437
+ const ogAttributes = node.attributes.map((attr) => ({ ...attr }));
438
+ const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
439
+ const closingElement = traversePath.node.closingElement;
440
+ if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
441
+ return;
442
+ }
443
+ const binding = traversePath.scope.getBinding(node.name.name);
444
+ let modulePath = "";
445
+ if (binding) {
446
+ if (!t.isImportDeclaration(binding.path.parent)) {
447
+ if (shouldPrintDebug) {
448
+ logger.info(` - Binding not import declaration, skip`);
449
+ }
450
+ return;
451
+ }
452
+ modulePath = binding.path.parent.source.value;
453
+ if (!(0, import_extractHelpers.isValidImport)(propsWithFileInfo, modulePath, binding.identifier.name)) {
454
+ if (shouldPrintDebug) {
455
+ logger.info(` - Binding not internal import or from components ${modulePath}`);
456
+ }
457
+ return;
458
+ }
459
+ }
460
+ const component = (0, import_extractHelpers.getValidComponent)(propsWithFileInfo, modulePath, node.name.name);
461
+ if (!component || !component.staticConfig) {
462
+ if (shouldPrintDebug) {
463
+ logger.info(` - No Tamagui conf on this: ${node.name.name}`);
464
+ }
465
+ return;
466
+ }
467
+ const originalNodeName = node.name.name;
468
+ res.found++;
469
+ const filePath = `./${(0, import_path.relative)(process.cwd(), sourcePath)}`;
470
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
471
+ const codePosition = `${filePath}:${lineNumbers}`;
472
+ const debugPropValue = node.attributes.filter(
473
+ (n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug"
474
+ ).map((n) => {
475
+ if (n.value === null)
476
+ return true;
477
+ if (t.isStringLiteral(n.value))
478
+ return n.value.value;
479
+ return false;
480
+ })[0];
481
+ if (debugPropValue) {
482
+ shouldPrintDebug = debugPropValue;
483
+ }
484
+ if (shouldPrintDebug) {
485
+ logger.info("\n");
486
+ logger.info(
487
+ `\x1B[33m%s\x1B[0m ${componentName} | ${codePosition} -------------------`
488
+ );
489
+ logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
490
+ }
491
+ if (shouldAddDebugProp && !disableDebugAttr) {
492
+ res.modified++;
493
+ node.attributes.unshift(
494
+ t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name))
495
+ );
496
+ if (componentName) {
497
+ node.attributes.unshift(
498
+ t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName))
499
+ );
500
+ }
501
+ node.attributes.unshift(
502
+ t.jsxAttribute(
503
+ t.jsxIdentifier("data-at"),
504
+ t.stringLiteral(`${(0, import_path.basename)(filePath)}:${lineNumbers}`)
505
+ )
506
+ );
507
+ }
508
+ if (disableExtraction) {
509
+ return;
510
+ }
511
+ try {
512
+ let evaluateAttribute2 = function(path) {
513
+ const attribute = path.node;
514
+ const attr = { type: "attr", value: attribute };
515
+ if (t.isJSXSpreadAttribute(attribute)) {
516
+ const arg = attribute.argument;
517
+ const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
518
+ if (conditional) {
519
+ const [test, alt, cons] = conditional;
520
+ if (!test)
521
+ throw new Error(`no test`);
522
+ if ([alt, cons].some((side) => side && !isStaticObject2(side))) {
523
+ if (shouldPrintDebug) {
524
+ logger.info(`not extractable ${alt} ${cons}`);
525
+ }
526
+ return attr;
527
+ }
528
+ return [
529
+ ...createTernariesFromObjectProperties2(test, alt) || [],
530
+ ...cons && createTernariesFromObjectProperties2(t.unaryExpression("!", test), cons) || []
531
+ ].map((ternary) => ({
532
+ type: "ternary",
533
+ value: ternary
534
+ }));
535
+ }
536
+ }
537
+ if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
538
+ if (shouldPrintDebug) {
539
+ logger.info(" ! inlining, spread attr");
540
+ }
541
+ inlined.set(`${Math.random()}`, "spread");
542
+ return attr;
543
+ }
544
+ const name = attribute.name.name;
545
+ if (excludeProps == null ? void 0 : excludeProps.has(name)) {
546
+ if (shouldPrintDebug) {
547
+ logger.info([" excluding prop", name].join(" "));
548
+ }
549
+ return null;
550
+ }
551
+ if (inlineProps.has(name)) {
552
+ inlined.set(name, name);
553
+ if (shouldPrintDebug) {
554
+ logger.info([" ! inlining, inline prop", name].join(" "));
555
+ }
556
+ return attr;
557
+ }
558
+ if (deoptProps.has(name)) {
559
+ shouldDeopt = true;
560
+ inlined.set(name, name);
561
+ if (shouldPrintDebug) {
562
+ logger.info([" ! inlining, deopted prop", name].join(" "));
563
+ }
564
+ return attr;
565
+ }
566
+ if (UNTOUCHED_PROPS[name]) {
567
+ return attr;
568
+ }
569
+ if (INLINE_EXTRACTABLE[name]) {
570
+ inlined.set(name, INLINE_EXTRACTABLE[name]);
571
+ return attr;
572
+ }
573
+ if (name.startsWith("data-")) {
574
+ return attr;
575
+ }
576
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
577
+ const shortname = name.slice(1);
578
+ if (import_core_node.mediaQueryConfig[shortname]) {
579
+ if (target === "native") {
580
+ shouldDeopt = true;
581
+ }
582
+ if (disableExtractInlineMedia) {
583
+ return attr;
584
+ }
585
+ const expression = attribute.value.expression;
586
+ if (!t.isJSXEmptyExpression(expression)) {
587
+ const ternaries2 = createTernariesFromObjectProperties2(
588
+ t.stringLiteral(shortname),
589
+ expression,
590
+ {
591
+ inlineMediaQuery: shortname
592
+ }
593
+ );
594
+ if (ternaries2) {
595
+ return ternaries2.map((value2) => ({
596
+ type: "ternary",
597
+ value: value2
598
+ }));
599
+ }
600
+ }
601
+ }
602
+ }
603
+ const [value, valuePath] = (() => {
604
+ if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
605
+ return [attribute.value.expression, path.get("value")];
606
+ } else {
607
+ return [attribute.value, path.get("value")];
608
+ }
609
+ })();
610
+ const remove = () => {
611
+ Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
612
+ };
613
+ if (name === "ref") {
614
+ if (shouldPrintDebug) {
615
+ logger.info([" ! inlining, ref", name].join(" "));
616
+ }
617
+ inlined.set("ref", "ref");
618
+ return attr;
619
+ }
620
+ if (name === "tag") {
621
+ return {
622
+ type: "attr",
623
+ value: path.node
624
+ };
625
+ }
626
+ if (disableExtractVariables === true) {
627
+ if (value) {
628
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
629
+ if (shouldPrintDebug) {
630
+ logger.info(
631
+ [` ! inlining, native disable extract: ${name} =`, value.value].join(" ")
632
+ );
633
+ }
634
+ inlined.set(name, true);
635
+ return attr;
636
+ }
637
+ }
638
+ }
639
+ if (name === "theme") {
640
+ inlined.set("theme", attr.value);
641
+ return attr;
642
+ }
643
+ const styleValue = attemptEvalSafe(value);
644
+ if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
645
+ let keys = [name];
646
+ let out = null;
647
+ out = staticConfig.propMapper(
648
+ name,
649
+ styleValue,
650
+ defaultTheme,
651
+ staticConfig.defaultProps,
652
+ { resolveVariablesAs: "auto" },
653
+ void 0,
654
+ void 0,
655
+ shouldPrintDebug
656
+ );
657
+ if (out) {
658
+ if (!Array.isArray(out)) {
659
+ logger.warn(`Error expected array but got`, out);
660
+ couldntParse = true;
661
+ shouldDeopt = true;
662
+ } else {
663
+ out = Object.fromEntries(out);
664
+ keys = Object.keys(out);
665
+ }
666
+ }
667
+ if (out) {
668
+ if (isTargetingHTML) {
669
+ out = (0, import_react_native_web_internals.createDOMProps)(isTextView ? "span" : "div", out);
670
+ delete out.className;
671
+ }
672
+ keys = Object.keys(out);
673
+ }
674
+ let didInline = false;
675
+ const attributes = keys.map((key) => {
676
+ const val = out[key];
677
+ if (isValidStyleKey(key, staticConfig)) {
678
+ return {
679
+ type: "style",
680
+ value: { [key]: styleValue },
681
+ name: key,
682
+ attr: path.node
683
+ };
684
+ }
685
+ if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") || key === "__source" || key === "__self") {
686
+ return attr;
687
+ }
688
+ if (shouldPrintDebug) {
689
+ logger.info(" ! inlining, non-static " + key);
690
+ }
691
+ didInline = true;
692
+ inlined.set(key, val);
693
+ return val;
694
+ });
695
+ if (didInline) {
696
+ if (shouldPrintDebug) {
697
+ logger.info(` bailing flattening due to attributes ${attributes}`);
698
+ }
699
+ return attr;
700
+ }
701
+ return attributes;
702
+ }
703
+ if (styleValue !== import_constants.FAILED_EVAL) {
704
+ if (inlineWhenUnflattened.has(name)) {
705
+ inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
706
+ }
707
+ if (isValidStyleKey(name, staticConfig)) {
708
+ if (shouldPrintDebug) {
709
+ logger.info(` style: ${name} = ${styleValue}`);
710
+ }
711
+ if (!(name in staticConfig.defaultProps)) {
712
+ if (!hasSetOptimized) {
713
+ res.optimized++;
714
+ hasSetOptimized = true;
715
+ }
716
+ }
717
+ return {
718
+ type: "style",
719
+ value: { [name]: styleValue },
720
+ name,
721
+ attr: path.node
722
+ };
723
+ } else {
724
+ if (variants[name]) {
725
+ variantValues.set(name, styleValue);
726
+ }
727
+ inlined.set(name, true);
728
+ return attr;
729
+ }
730
+ }
731
+ if (t.isBinaryExpression(value)) {
732
+ if (shouldPrintDebug) {
733
+ logger.info(` binary expression ${name} = ${value}`);
734
+ }
735
+ const { operator, left, right } = value;
736
+ const lVal = attemptEvalSafe(left);
737
+ const rVal = attemptEvalSafe(right);
738
+ if (shouldPrintDebug) {
739
+ logger.info(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
740
+ }
741
+ if (lVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
742
+ const ternary = addBinaryConditional(operator, left, right);
743
+ if (ternary)
744
+ return ternary;
745
+ }
746
+ if (rVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(left)) {
747
+ const ternary = addBinaryConditional(operator, right, left);
748
+ if (ternary)
749
+ return ternary;
750
+ }
751
+ if (shouldPrintDebug) {
752
+ logger.info(` evalBinaryExpression cant extract`);
753
+ }
754
+ inlined.set(name, true);
755
+ return attr;
756
+ }
757
+ const staticConditional = getStaticConditional(value);
758
+ if (staticConditional) {
759
+ if (shouldPrintDebug === "verbose") {
760
+ logger.info(` static conditional ${name} ${value}`);
761
+ }
762
+ return { type: "ternary", value: staticConditional };
763
+ }
764
+ const staticLogical = getStaticLogical(value);
765
+ if (staticLogical) {
766
+ if (shouldPrintDebug === "verbose") {
767
+ logger.info(` static ternary ${name} = ${value}`);
768
+ }
769
+ return { type: "ternary", value: staticLogical };
770
+ }
771
+ inlined.set(name, true);
772
+ if (shouldPrintDebug) {
773
+ logger.info(` ! inline no match ${name} ${value}`);
774
+ }
775
+ return attr;
776
+ function addBinaryConditional(operator, staticExpr, cond) {
777
+ if (getStaticConditional(cond)) {
778
+ const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
779
+ const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
780
+ if (shouldPrintDebug) {
781
+ logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
782
+ }
783
+ return {
784
+ type: "ternary",
785
+ value: {
786
+ test: cond.test,
787
+ remove,
788
+ alternate: { [name]: alt },
789
+ consequent: { [name]: cons }
790
+ }
791
+ };
792
+ }
793
+ return null;
794
+ }
795
+ function getStaticConditional(value2) {
796
+ if (t.isConditionalExpression(value2)) {
797
+ try {
798
+ const aVal = attemptEval(value2.alternate);
799
+ const cVal = attemptEval(value2.consequent);
800
+ if (shouldPrintDebug) {
801
+ const type = value2.test.type;
802
+ logger.info([" static ternary", type, cVal, aVal].join(" "));
803
+ }
804
+ return {
805
+ test: value2.test,
806
+ remove,
807
+ consequent: { [name]: cVal },
808
+ alternate: { [name]: aVal }
809
+ };
810
+ } catch (err) {
811
+ if (shouldPrintDebug) {
812
+ logger.info([" cant eval ternary", err.message].join(" "));
813
+ }
814
+ }
815
+ }
816
+ return null;
817
+ }
818
+ function getStaticLogical(value2) {
819
+ if (t.isLogicalExpression(value2)) {
820
+ if (value2.operator === "&&") {
821
+ try {
822
+ const val = attemptEval(value2.right);
823
+ if (shouldPrintDebug) {
824
+ logger.info([" staticLogical", value2.left, name, val].join(" "));
825
+ }
826
+ return {
827
+ test: value2.left,
828
+ remove,
829
+ consequent: { [name]: val },
830
+ alternate: null
831
+ };
832
+ } catch (err) {
833
+ if (shouldPrintDebug) {
834
+ logger.info([" cant static eval logical", err].join(" "));
835
+ }
836
+ }
837
+ }
838
+ }
839
+ return null;
840
+ }
841
+ }, isStaticObject2 = function(obj) {
842
+ return t.isObjectExpression(obj) && obj.properties.every((prop) => {
843
+ if (!t.isObjectProperty(prop)) {
844
+ logger.info(["not object prop", prop].join(" "));
845
+ return false;
846
+ }
847
+ const propName = prop.key["name"];
848
+ if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
849
+ if (shouldPrintDebug) {
850
+ logger.info([" not a valid style prop!", propName].join(" "));
851
+ }
852
+ return false;
853
+ }
854
+ return true;
855
+ });
856
+ }, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
857
+ if (!side) {
858
+ return null;
859
+ }
860
+ if (!isStaticObject2(side)) {
861
+ throw new Error("not extractable");
862
+ }
863
+ return side.properties.flatMap((property) => {
864
+ if (!t.isObjectProperty(property)) {
865
+ throw new Error("expected object property");
866
+ }
867
+ if (t.isIdentifier(property.key)) {
868
+ const key = property.key.name;
869
+ const mediaQueryKey = key.slice(1);
870
+ const isMediaQuery = key[0] === "$" && import_core_node.mediaQueryConfig[mediaQueryKey];
871
+ if (isMediaQuery) {
872
+ if (t.isExpression(property.value)) {
873
+ const ternaries2 = createTernariesFromObjectProperties2(
874
+ t.stringLiteral(mediaQueryKey),
875
+ property.value,
876
+ {
877
+ inlineMediaQuery: mediaQueryKey
878
+ }
879
+ );
880
+ if (ternaries2) {
881
+ return ternaries2.map((value) => ({
882
+ ...ternaryPartial,
883
+ ...value,
884
+ test: t.logicalExpression("&&", value.test, test)
885
+ }));
886
+ } else {
887
+ logger.info(["\u26A0\uFE0F no ternaries?", property].join(" "));
888
+ }
889
+ } else {
890
+ logger.info(["\u26A0\uFE0F not expression", property].join(" "));
891
+ }
892
+ }
893
+ }
894
+ if (t.isConditionalExpression(property.value)) {
895
+ const [truthy, falsy] = [
896
+ t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
897
+ t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
898
+ ].map((x) => attemptEval(x));
899
+ return [
900
+ createTernary({
901
+ remove() {
902
+ },
903
+ ...ternaryPartial,
904
+ test: t.logicalExpression("&&", test, property.value.test),
905
+ consequent: truthy,
906
+ alternate: null
907
+ }),
908
+ createTernary({
909
+ ...ternaryPartial,
910
+ test: t.logicalExpression(
911
+ "&&",
912
+ test,
913
+ t.unaryExpression("!", property.value.test)
914
+ ),
915
+ consequent: falsy,
916
+ alternate: null,
917
+ remove() {
918
+ }
919
+ })
920
+ ];
921
+ }
922
+ const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
923
+ const consequent = attemptEval(obj);
924
+ return createTernary({
925
+ remove() {
926
+ },
927
+ ...ternaryPartial,
928
+ test,
929
+ consequent,
930
+ alternate: null
931
+ });
932
+ });
933
+ }, splitVariants2 = function(style) {
934
+ var _a3;
935
+ const variants2 = {};
936
+ const styles = {};
937
+ for (const key in style) {
938
+ if ((_a3 = staticConfig.variants) == null ? void 0 : _a3[key]) {
939
+ variants2[key] = style[key];
940
+ } else {
941
+ styles[key] = style[key];
942
+ }
943
+ }
944
+ return {
945
+ variants: variants2,
946
+ styles
947
+ };
948
+ }, expandStylesWithoutVariants2 = function(style) {
949
+ const { variants: variants2, styles } = splitVariants2(style);
950
+ return {
951
+ ...(0, import_core_node.expandStyles)(styles),
952
+ ...variants2
953
+ };
954
+ }, mergeStyles2 = function(prev2, nextIn) {
955
+ const next = expandStylesWithoutVariants2(nextIn);
956
+ for (const key in next) {
957
+ if (import_core_node.pseudoDescriptors[key]) {
958
+ prev2[key] = prev2[key] || {};
959
+ if (shouldPrintDebug) {
960
+ if (!next[key] || !prev2[key]) {
961
+ logger.info(["warn: missing", key, prev2, next].join(" "));
962
+ }
963
+ }
964
+ Object.assign(prev2[key], next[key]);
965
+ } else {
966
+ prev2[key] = next[key];
967
+ }
968
+ }
969
+ };
970
+ var evaluateAttribute = evaluateAttribute2, isStaticObject = isStaticObject2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, splitVariants = splitVariants2, expandStylesWithoutVariants = expandStylesWithoutVariants2, mergeStyles = mergeStyles2;
971
+ const { staticConfig } = component;
972
+ const variants = staticConfig.variants || {};
973
+ const isTextView = staticConfig.isText || false;
974
+ const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
975
+ let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
976
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
977
+ const attr = path.node;
978
+ if (t.isJSXSpreadAttribute(attr))
979
+ return;
980
+ if (attr.name.name !== "tag")
981
+ return;
982
+ const val = attr.value;
983
+ if (!t.isStringLiteral(val))
984
+ return;
985
+ tagName = val.value;
986
+ });
987
+ const flatNode = getFlattenedNode == null ? void 0 : getFlattenedNode({ isTextView, tag: tagName });
988
+ const inlineProps = /* @__PURE__ */ new Set([
989
+ ...restProps.inlineProps || [],
990
+ ...staticConfig.inlineProps || []
991
+ ]);
992
+ const deoptProps = /* @__PURE__ */ new Set([
993
+ "animation",
994
+ ...restProps.deoptProps || [],
995
+ ...staticConfig.deoptProps || []
996
+ ]);
997
+ const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
998
+ const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(
999
+ traversePath.scope,
1000
+ importsWhitelist,
1001
+ sourcePath,
1002
+ bindingCache,
1003
+ shouldPrintDebug
1004
+ );
1005
+ const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
1006
+ props: propsWithFileInfo,
1007
+ staticNamespace,
1008
+ sourcePath,
1009
+ traversePath,
1010
+ shouldPrintDebug
1011
+ });
1012
+ const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
1013
+ if (shouldPrintDebug) {
1014
+ logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
1015
+ }
1016
+ const flattenedAttrs = [];
1017
+ traversePath.get("openingElement").get("attributes").forEach((path) => {
1018
+ const attr = path.node;
1019
+ if (!t.isJSXSpreadAttribute(attr)) {
1020
+ flattenedAttrs.push(attr);
1021
+ return;
1022
+ }
1023
+ let arg;
1024
+ try {
1025
+ arg = attemptEval(attr.argument);
1026
+ } catch (e) {
1027
+ if (shouldPrintDebug) {
1028
+ logger.info([" couldnt parse spread", e.message].join(" "));
1029
+ }
1030
+ flattenedAttrs.push(attr);
1031
+ return;
1032
+ }
1033
+ if (arg !== void 0) {
1034
+ try {
1035
+ if (typeof arg !== "object" || arg == null) {
1036
+ if (shouldPrintDebug) {
1037
+ logger.info([" non object or null arg", arg].join(" "));
1038
+ }
1039
+ flattenedAttrs.push(attr);
1040
+ } else {
1041
+ for (const k in arg) {
1042
+ const value = arg[k];
1043
+ if (!value && typeof value === "object") {
1044
+ logger.error(["Unhandled null prop", k, value, arg].join(" "));
1045
+ continue;
1046
+ }
1047
+ flattenedAttrs.push(
1048
+ t.jsxAttribute(
1049
+ t.jsxIdentifier(k),
1050
+ t.jsxExpressionContainer((0, import_literalToAst.literalToAst)(value))
1051
+ )
1052
+ );
1053
+ }
1054
+ }
1055
+ } catch (err) {
1056
+ logger.warn(`cant parse spread, caught err ${err}`);
1057
+ couldntParse = true;
1058
+ }
1059
+ }
1060
+ });
1061
+ if (couldntParse) {
1062
+ return;
1063
+ }
1064
+ tm.mark("jsx-element-flattened", !!shouldPrintDebug);
1065
+ node.attributes = flattenedAttrs;
1066
+ let attrs = [];
1067
+ let shouldDeopt = false;
1068
+ const inlined = /* @__PURE__ */ new Map();
1069
+ const variantValues = /* @__PURE__ */ new Map();
1070
+ let hasSetOptimized = false;
1071
+ const inlineWhenUnflattenedOGVals = {};
1072
+ attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
1073
+ var _a3;
1074
+ try {
1075
+ const res2 = evaluateAttribute2(path);
1076
+ tm.mark("jsx-element-evaluate-attr", !!shouldPrintDebug);
1077
+ if (!res2) {
1078
+ path.remove();
1079
+ }
1080
+ return res2;
1081
+ } catch (err) {
1082
+ if (shouldPrintDebug) {
1083
+ logger.info(
1084
+ [
1085
+ "Recoverable error extracting attribute",
1086
+ err.message,
1087
+ shouldPrintDebug === "verbose" ? err.stack : ""
1088
+ ].join(" ")
1089
+ );
1090
+ if (shouldPrintDebug === "verbose") {
1091
+ logger.info(`node ${(_a3 = path.node) == null ? void 0 : _a3.type}`);
1092
+ }
1093
+ }
1094
+ inlined.set(`${Math.random()}`, "spread");
1095
+ return {
1096
+ type: "attr",
1097
+ value: path.node
1098
+ };
1099
+ }
1100
+ }).flat(4).filter(import_extractHelpers.isPresent);
1101
+ if (shouldPrintDebug) {
1102
+ logger.info(
1103
+ [" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" ")
1104
+ );
1105
+ }
1106
+ if (couldntParse || shouldDeopt) {
1107
+ if (shouldPrintDebug) {
1108
+ logger.info([` avoid optimizing:`, { couldntParse, shouldDeopt }].join(" "));
1109
+ }
1110
+ node.attributes = ogAttributes;
1111
+ return;
1112
+ }
1113
+ node.attributes = attrs.filter(isAttr).map((x) => x.value);
1114
+ const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
1115
+ if (parentFn) {
1116
+ modifiedComponents.add(parentFn);
1117
+ }
1118
+ let ternaries = [];
1119
+ attrs = attrs.reduce((out, cur) => {
1120
+ const next = attrs[attrs.indexOf(cur) + 1];
1121
+ if (cur.type === "ternary") {
1122
+ ternaries.push(cur.value);
1123
+ }
1124
+ if ((!next || next.type !== "ternary") && ternaries.length) {
1125
+ const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map(
1126
+ ({ alternate, consequent, ...rest }) => {
1127
+ return {
1128
+ type: "ternary",
1129
+ value: {
1130
+ ...rest,
1131
+ alternate: alternate || null,
1132
+ consequent: consequent || null
1133
+ }
1134
+ };
1135
+ }
1136
+ );
1137
+ try {
1138
+ return [...out, ...normalized];
1139
+ } finally {
1140
+ if (shouldPrintDebug) {
1141
+ logger.info(
1142
+ ` normalizeTernaries (${ternaries.length} => ${normalized.length})`
1143
+ );
1144
+ }
1145
+ ternaries = [];
1146
+ }
1147
+ }
1148
+ if (cur.type === "ternary") {
1149
+ return out;
1150
+ }
1151
+ out.push(cur);
1152
+ return out;
1153
+ }, []).flat();
1154
+ const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
1155
+ const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
1156
+ const themeVal = inlined.get("theme");
1157
+ if (target !== "native") {
1158
+ inlined.delete("theme");
1159
+ }
1160
+ for (const [key] of [...inlined]) {
1161
+ const isStaticObjectVariant = ((_a2 = staticConfig.variants) == null ? void 0 : _a2[key]) && variantValues.has(key);
1162
+ if (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) {
1163
+ inlined.delete(key);
1164
+ }
1165
+ }
1166
+ const canFlattenProps = inlined.size === 0;
1167
+ let shouldFlatten = Boolean(
1168
+ flatNode && !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true)
1169
+ );
1170
+ const shouldWrapTheme = shouldFlatten && themeVal;
1171
+ const usedThemeKeys = /* @__PURE__ */ new Set();
1172
+ if (disableExtractVariables) {
1173
+ themeAccessListeners.add((key) => {
1174
+ shouldFlatten = false;
1175
+ usedThemeKeys.add(key);
1176
+ if (shouldPrintDebug === "verbose") {
1177
+ logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
1178
+ }
1179
+ });
1180
+ }
1181
+ if (shouldPrintDebug) {
1182
+ try {
1183
+ logger.info([" flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]].join(" "));
1184
+ } catch {
1185
+ }
1186
+ }
1187
+ if (shouldFlatten && shouldWrapTheme) {
1188
+ if (!programPath) {
1189
+ console.warn(
1190
+ `No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
1191
+ );
1192
+ } else {
1193
+ if (shouldPrintDebug) {
1194
+ logger.info([" - wrapping theme", themeVal].join(" "));
1195
+ }
1196
+ attrs = attrs.filter(
1197
+ (x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true
1198
+ );
1199
+ if (!hasImportedTheme) {
1200
+ hasImportedTheme = true;
1201
+ programPath.node.body.push(
1202
+ t.importDeclaration(
1203
+ [t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))],
1204
+ t.stringLiteral("@tamagui/core")
1205
+ )
1206
+ );
1207
+ }
1208
+ traversePath.replaceWith(
1209
+ t.jsxElement(
1210
+ t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
1211
+ t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
1212
+ ]),
1213
+ t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")),
1214
+ [traversePath.node]
1215
+ )
1216
+ );
1217
+ }
1218
+ }
1219
+ if (shouldFlatten) {
1220
+ const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
1221
+ if (!isValidStyleKey(key, staticConfig)) {
1222
+ return [];
1223
+ }
1224
+ const value = staticConfig.defaultProps[key];
1225
+ const name = tamaguiConfig.shorthands[key] || key;
1226
+ if (value === void 0) {
1227
+ logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
1228
+ shouldDeopt = true;
1229
+ return;
1230
+ }
1231
+ const attr = {
1232
+ type: "style",
1233
+ name,
1234
+ value: { [name]: value }
1235
+ };
1236
+ return attr;
1237
+ });
1238
+ if (defaultStyleAttrs.length) {
1239
+ attrs = [...defaultStyleAttrs, ...attrs];
1240
+ }
1241
+ }
1242
+ if (shouldDeopt || !shouldFlatten) {
1243
+ if (shouldPrintDebug) {
1244
+ logger.info(`Deopting`);
1245
+ }
1246
+ node.attributes = ogAttributes;
1247
+ return;
1248
+ }
1249
+ if (shouldPrintDebug) {
1250
+ logger.info(
1251
+ [" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" ")
1252
+ );
1253
+ }
1254
+ const state = {
1255
+ noClassNames: false,
1256
+ focus: false,
1257
+ hover: false,
1258
+ unmounted: false,
1259
+ press: false,
1260
+ pressIn: false
1261
+ };
1262
+ let foundStaticProps = {};
1263
+ for (const key in attrs) {
1264
+ const cur = attrs[key];
1265
+ if (cur.type === "style") {
1266
+ foundStaticProps = {
1267
+ ...foundStaticProps,
1268
+ ...expandStylesWithoutVariants2(cur.value)
1269
+ };
1270
+ continue;
1271
+ }
1272
+ if (cur.type === "attr") {
1273
+ if (t.isJSXSpreadAttribute(cur.value)) {
1274
+ continue;
1275
+ }
1276
+ if (!t.isJSXIdentifier(cur.value.name)) {
1277
+ continue;
1278
+ }
1279
+ const key2 = cur.value.name.name;
1280
+ const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
1281
+ if (value !== import_constants.FAILED_EVAL) {
1282
+ foundStaticProps = {
1283
+ ...foundStaticProps,
1284
+ [key2]: value
1285
+ };
1286
+ }
1287
+ }
1288
+ }
1289
+ const completeProps = {};
1290
+ for (const key in staticConfig.defaultProps) {
1291
+ if (!(key in foundStaticProps)) {
1292
+ completeProps[key] = staticConfig.defaultProps[key];
1293
+ }
1294
+ }
1295
+ for (const key in foundStaticProps) {
1296
+ completeProps[key] = foundStaticProps[key];
1297
+ }
1298
+ attrs = attrs.reduce((acc, cur) => {
1299
+ if (!cur)
1300
+ return acc;
1301
+ if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
1302
+ if (shouldFlatten) {
1303
+ const name = cur.value.name.name;
1304
+ if (typeof name === "string") {
1305
+ if (name === "tag") {
1306
+ return acc;
1307
+ }
1308
+ if (variants[name] && variantValues.has(name)) {
1309
+ let out = Object.fromEntries(
1310
+ staticConfig.propMapper(
1311
+ name,
1312
+ variantValues.get(name),
1313
+ defaultTheme,
1314
+ completeProps,
1315
+ { ...state, resolveVariablesAs: "auto" },
1316
+ void 0,
1317
+ void 0,
1318
+ shouldPrintDebug
1319
+ ) || []
1320
+ );
1321
+ if (out && isTargetingHTML) {
1322
+ const cn = out.className;
1323
+ out = (0, import_react_native_web_internals.createDOMProps)(isTextView ? "span" : "div", out);
1324
+ out.className = cn;
1325
+ }
1326
+ if (shouldPrintDebug) {
1327
+ logger.info([" - expanded variant", name, out].join(" "));
1328
+ }
1329
+ for (const key2 in out) {
1330
+ const value2 = out[key2];
1331
+ if (isValidStyleKey(key2, staticConfig)) {
1332
+ acc.push({
1333
+ type: "style",
1334
+ value: { [key2]: value2 },
1335
+ name: key2,
1336
+ attr: cur.value
1337
+ });
1338
+ } else {
1339
+ acc.push({
1340
+ type: "attr",
1341
+ value: t.jsxAttribute(
1342
+ t.jsxIdentifier(key2),
1343
+ t.jsxExpressionContainer(
1344
+ typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)
1345
+ )
1346
+ )
1347
+ });
1348
+ }
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+ }
1354
+ if (cur.type !== "style") {
1355
+ acc.push(cur);
1356
+ return acc;
1357
+ }
1358
+ let key = Object.keys(cur.value)[0];
1359
+ const value = cur.value[key];
1360
+ const fullKey = tamaguiConfig.shorthands[key];
1361
+ if (fullKey) {
1362
+ cur.value = { [fullKey]: value };
1363
+ key = fullKey;
1364
+ }
1365
+ if (disableExtractVariables) {
1366
+ if (value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey))) {
1367
+ if (shouldPrintDebug) {
1368
+ logger.info([` keeping variable inline: ${key} =`, value].join(" "));
1369
+ }
1370
+ acc.push({
1371
+ type: "attr",
1372
+ value: t.jsxAttribute(
1373
+ t.jsxIdentifier(key),
1374
+ t.jsxExpressionContainer(t.stringLiteral(value))
1375
+ )
1376
+ });
1377
+ return acc;
1378
+ }
1379
+ }
1380
+ acc.push(cur);
1381
+ return acc;
1382
+ }, []);
1383
+ tm.mark("jsx-element-expanded", !!shouldPrintDebug);
1384
+ if (shouldPrintDebug) {
1385
+ logger.info(
1386
+ [" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" ")
1387
+ );
1388
+ }
1389
+ let prev = null;
1390
+ attrs = attrs.reduce((acc, cur) => {
1391
+ if (cur.type === "style") {
1392
+ const key = Object.keys(cur.value)[0];
1393
+ const value = cur.value[key];
1394
+ const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !import_core_node.pseudoDescriptors[key] && !key.startsWith("data-");
1395
+ if (shouldKeepOriginalAttr) {
1396
+ if (shouldPrintDebug) {
1397
+ logger.info([" - keeping as non-style", key].join(" "));
1398
+ }
1399
+ prev = cur;
1400
+ acc.push({
1401
+ type: "attr",
1402
+ value: t.jsxAttribute(
1403
+ t.jsxIdentifier(key),
1404
+ t.jsxExpressionContainer(
1405
+ typeof value === "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)
1406
+ )
1407
+ )
1408
+ });
1409
+ acc.push(cur);
1410
+ return acc;
1411
+ }
1412
+ if ((prev == null ? void 0 : prev.type) === "style") {
1413
+ mergeStyles2(prev.value, cur.value);
1414
+ return acc;
1415
+ }
1416
+ }
1417
+ prev = cur;
1418
+ acc.push(cur);
1419
+ return acc;
1420
+ }, []);
1421
+ if (shouldPrintDebug) {
1422
+ logger.info(
1423
+ [" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" ")
1424
+ );
1425
+ logger.info(
1426
+ [" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps))].join(" ")
1427
+ );
1428
+ logger.info([" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps))].join(" "));
1429
+ logger.info([" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps))].join(" "));
1430
+ }
1431
+ const getStyles = (props, debugName = "") => {
1432
+ if (!props || !Object.keys(props).length) {
1433
+ if (shouldPrintDebug)
1434
+ logger.info([" getStyles() no props"].join(" "));
1435
+ return {};
1436
+ }
1437
+ if (excludeProps && !!excludeProps.size) {
1438
+ for (const key in props) {
1439
+ if (excludeProps.has(key)) {
1440
+ if (shouldPrintDebug)
1441
+ logger.info([" delete excluded", key].join(" "));
1442
+ delete props[key];
1443
+ }
1444
+ }
1445
+ }
1446
+ try {
1447
+ const out = (0, import_core_node.getSplitStyles)(
1448
+ props,
1449
+ staticConfig,
1450
+ defaultTheme,
1451
+ {
1452
+ ...state,
1453
+ fallbackProps: completeProps
1454
+ },
1455
+ void 0,
1456
+ void 0,
1457
+ void 0,
1458
+ debugPropValue
1459
+ );
1460
+ const outStyle = {
1461
+ ...out.style,
1462
+ ...out.pseudos
1463
+ };
1464
+ return outStyle;
1465
+ } catch (err) {
1466
+ logger.info(["error", err.message, err.stack].join(" "));
1467
+ return {};
1468
+ }
1469
+ };
1470
+ const completeStyles = getStyles(completeProps, "completeStyles");
1471
+ if (!completeStyles) {
1472
+ throw new Error(`Impossible, no styles`);
1473
+ }
1474
+ const isNativeNotFlat = !shouldFlatten && target === "native";
1475
+ if (isNativeNotFlat) {
1476
+ if (shouldPrintDebug) {
1477
+ logger.info(`Disabled flattening except for simple cases on native for now`);
1478
+ }
1479
+ node.attributes = ogAttributes;
1480
+ return null;
1481
+ }
1482
+ let getStyleError = null;
1483
+ for (const attr of attrs) {
1484
+ try {
1485
+ switch (attr.type) {
1486
+ case "ternary": {
1487
+ const a = getStyles(attr.value.alternate, "ternary.alternate");
1488
+ const c = getStyles(attr.value.consequent, "ternary.consequent");
1489
+ if (a)
1490
+ attr.value.alternate = a;
1491
+ if (c)
1492
+ attr.value.consequent = c;
1493
+ if (shouldPrintDebug)
1494
+ logger.info([" => tern ", (0, import_extractHelpers.attrStr)(attr)].join(" "));
1495
+ continue;
1496
+ }
1497
+ case "style": {
1498
+ const styles = getStyles(attr.value, "style");
1499
+ if (styles) {
1500
+ attr.value = styles;
1501
+ }
1502
+ if (shouldPrintDebug)
1503
+ logger.info([" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value))].join(" "));
1504
+ if (shouldPrintDebug)
1505
+ logger.info([" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles))].join(" "));
1506
+ continue;
1507
+ }
1508
+ }
1509
+ } catch (err) {
1510
+ getStyleError = err;
1511
+ }
1512
+ }
1513
+ if (shouldPrintDebug) {
1514
+ logger.info([" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
1515
+ }
1516
+ tm.mark("jsx-element-styles", !!shouldPrintDebug);
1517
+ if (getStyleError) {
1518
+ logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
1519
+ node.attributes = ogAttributes;
1520
+ return null;
1521
+ }
1522
+ const existingStyleKeys = /* @__PURE__ */ new Set();
1523
+ for (let i = attrs.length - 1; i >= 0; i--) {
1524
+ const attr = attrs[i];
1525
+ if (shouldFlatten) {
1526
+ if (attr.type === "attr") {
1527
+ if (t.isJSXAttribute(attr.value)) {
1528
+ if (t.isJSXIdentifier(attr.value.name)) {
1529
+ const name = attr.value.name.name;
1530
+ if (INLINE_EXTRACTABLE[name]) {
1531
+ attr.value.name.name = INLINE_EXTRACTABLE[name];
1532
+ }
1533
+ }
1534
+ }
1535
+ }
1536
+ }
1537
+ if (attr.type === "style") {
1538
+ for (const key in attr.value) {
1539
+ if (existingStyleKeys.has(key)) {
1540
+ if (shouldPrintDebug) {
1541
+ logger.info([` >> delete existing ${key}`].join(" "));
1542
+ }
1543
+ delete attr.value[key];
1544
+ } else {
1545
+ existingStyleKeys.add(key);
1546
+ }
1547
+ }
1548
+ }
1549
+ }
1550
+ if (!shouldFlatten) {
1551
+ if (inlineWhenUnflattened.size) {
1552
+ for (const [index, attr] of attrs.entries()) {
1553
+ if (attr.type === "style") {
1554
+ for (const key in attr.value) {
1555
+ if (!inlineWhenUnflattened.has(key))
1556
+ continue;
1557
+ const val = inlineWhenUnflattenedOGVals[key];
1558
+ if (val) {
1559
+ delete attr.value[key];
1560
+ attrs.splice(index - 1, 0, val.attr);
1561
+ } else {
1562
+ delete attr.value[key];
1563
+ }
1564
+ }
1565
+ }
1566
+ }
1567
+ }
1568
+ }
1569
+ if (shouldFlatten) {
1570
+ if (shouldPrintDebug) {
1571
+ logger.info([" [\u2705] flattening", originalNodeName, flatNode].join(" "));
1572
+ }
1573
+ node.name.name = flatNode;
1574
+ res.flattened++;
1575
+ if (closingElement) {
1576
+ closingElement.name.name = flatNode;
1577
+ }
1578
+ }
1579
+ if (shouldPrintDebug) {
1580
+ logger.info([` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
1581
+ logger.info(` - attrs (end):
1582
+ ${(0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))}`);
1583
+ }
1584
+ onExtractTag({
1585
+ parserProps: propsWithFileInfo,
1586
+ attrs,
1587
+ node,
1588
+ lineNumbers,
1589
+ filePath,
1590
+ attemptEval,
1591
+ jsxPath: traversePath,
1592
+ originalNodeName,
1593
+ isFlattened: shouldFlatten,
1594
+ programPath,
1595
+ completeProps,
1596
+ staticConfig
1597
+ });
1598
+ } finally {
1599
+ if (debugPropValue) {
1600
+ shouldPrintDebug = ogDebug;
1601
+ }
1602
+ }
1603
+ }
1604
+ });
1605
+ tm.mark("jsx-done", !!shouldPrintDebug);
1606
+ if (modifiedComponents.size) {
1607
+ const all = Array.from(modifiedComponents);
1608
+ if (shouldPrintDebug) {
1609
+ logger.info(` [\u{1FA9D}] hook check ${all.length}`);
1610
+ }
1611
+ for (const comp of all) {
1612
+ (0, import_removeUnusedHooks.removeUnusedHooks)(comp, shouldPrintDebug);
1613
+ }
1614
+ }
1615
+ tm.done(shouldPrintDebug === "verbose");
1616
+ return res;
1617
+ }
1618
+ }
1619
+ // Annotate the CommonJS export names for ESM import in node:
1620
+ 0 && (module.exports = {
1621
+ createExtractor
1622
+ });
1623
+ //# sourceMappingURL=createExtractor.js.map