@tamagui/static 1.0.1-beta.21 → 1.0.1-beta.210

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