@tamagui/static 1.0.1-beta.18 → 1.0.1-beta.181

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