@tamagui/static 1.0.1-beta.140 → 1.0.1-beta.143

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