@tamagui/static 1.0.1-beta.19 → 1.0.1-beta.191

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