@tamagui/static 1.135.3 → 1.135.4-1761748186554

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 (181) hide show
  1. package/dist/check-dep-versions.mjs +268 -0
  2. package/dist/check-dep-versions.mjs.map +1 -0
  3. package/dist/checkDeps.mjs +33 -0
  4. package/dist/checkDeps.mjs.map +1 -0
  5. package/dist/constants.mjs +50 -0
  6. package/dist/constants.mjs.map +1 -0
  7. package/dist/exports.mjs +42 -0
  8. package/dist/exports.mjs.map +1 -0
  9. package/dist/extractor/accessSafe.mjs +47 -0
  10. package/dist/extractor/accessSafe.mjs.map +1 -0
  11. package/dist/extractor/babelParse.mjs +55 -0
  12. package/dist/extractor/babelParse.mjs.map +1 -0
  13. package/dist/extractor/bundle.mjs +149 -0
  14. package/dist/extractor/bundle.mjs.map +1 -0
  15. package/dist/extractor/bundleConfig.mjs +331 -0
  16. package/dist/extractor/bundleConfig.mjs.map +1 -0
  17. package/dist/extractor/concatClassName.mjs +79 -0
  18. package/dist/extractor/concatClassName.mjs.map +1 -0
  19. package/dist/extractor/createEvaluator.mjs +76 -0
  20. package/dist/extractor/createEvaluator.mjs.map +1 -0
  21. package/dist/extractor/createExtractor.mjs +976 -0
  22. package/dist/extractor/createExtractor.mjs.map +1 -0
  23. package/dist/extractor/createLogger.mjs +46 -0
  24. package/dist/extractor/createLogger.mjs.map +1 -0
  25. package/dist/extractor/errors.mjs +27 -0
  26. package/dist/extractor/errors.mjs.map +1 -0
  27. package/dist/extractor/esbuildAliasPlugin.mjs +45 -0
  28. package/dist/extractor/esbuildAliasPlugin.mjs.map +1 -0
  29. package/dist/extractor/esbuildTsconfigPaths.mjs +85 -0
  30. package/dist/extractor/esbuildTsconfigPaths.mjs.map +1 -0
  31. package/dist/extractor/evaluateAstNode.mjs +84 -0
  32. package/dist/extractor/evaluateAstNode.mjs.map +1 -0
  33. package/dist/extractor/extractHelpers.mjs +121 -0
  34. package/dist/extractor/extractHelpers.mjs.map +1 -0
  35. package/dist/extractor/extractMediaStyle.mjs +129 -0
  36. package/dist/extractor/extractMediaStyle.mjs.map +1 -0
  37. package/dist/extractor/extractToClassNames.mjs +304 -0
  38. package/dist/extractor/extractToClassNames.mjs.map +1 -0
  39. package/dist/extractor/extractToNative.mjs +262 -0
  40. package/dist/extractor/extractToNative.mjs.map +1 -0
  41. package/dist/extractor/findTopmostFunction.mjs +35 -0
  42. package/dist/extractor/findTopmostFunction.mjs.map +1 -0
  43. package/dist/extractor/{generatedUid.native.js → generatedUid.mjs} +26 -23
  44. package/dist/extractor/generatedUid.mjs.map +1 -0
  45. package/dist/extractor/getPrefixLogs.mjs +30 -0
  46. package/dist/extractor/getPrefixLogs.mjs.map +1 -0
  47. package/dist/extractor/getPropValueFromAttributes.mjs +68 -0
  48. package/dist/extractor/getPropValueFromAttributes.mjs.map +1 -0
  49. package/dist/extractor/getSourceModule.mjs +65 -0
  50. package/dist/extractor/getSourceModule.mjs.map +1 -0
  51. package/dist/extractor/getStaticBindingsForScope.mjs +149 -0
  52. package/dist/extractor/getStaticBindingsForScope.mjs.map +1 -0
  53. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.mjs +36 -0
  54. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.mjs.map +1 -0
  55. package/dist/extractor/literalToAst.mjs +85 -0
  56. package/dist/extractor/literalToAst.mjs.map +1 -0
  57. package/dist/extractor/loadFile.mjs +12 -0
  58. package/dist/extractor/loadFile.mjs.map +1 -0
  59. package/dist/extractor/loadTamagui.mjs +296 -0
  60. package/dist/extractor/loadTamagui.mjs.map +1 -0
  61. package/dist/extractor/logLines.mjs +36 -0
  62. package/dist/extractor/logLines.mjs.map +1 -0
  63. package/dist/extractor/{normalizeTernaries.native.js → normalizeTernaries.mjs} +45 -31
  64. package/dist/extractor/normalizeTernaries.mjs.map +1 -0
  65. package/dist/extractor/propsToFontFamilyCache.mjs +39 -0
  66. package/dist/extractor/propsToFontFamilyCache.mjs.map +1 -0
  67. package/dist/extractor/regenerateConfig.mjs +145 -0
  68. package/dist/extractor/regenerateConfig.mjs.map +1 -0
  69. package/dist/extractor/removeUnusedHooks.mjs +77 -0
  70. package/dist/extractor/removeUnusedHooks.mjs.map +1 -0
  71. package/dist/extractor/timer.mjs +44 -0
  72. package/dist/extractor/timer.mjs.map +1 -0
  73. package/dist/extractor/{validHTMLAttributes.native.js → validHTMLAttributes.mjs} +17 -16
  74. package/dist/extractor/validHTMLAttributes.mjs.map +1 -0
  75. package/dist/extractor/watchTamaguiConfig.mjs +59 -0
  76. package/dist/extractor/watchTamaguiConfig.mjs.map +1 -0
  77. package/dist/getPragmaOptions.mjs +55 -0
  78. package/dist/getPragmaOptions.mjs.map +1 -0
  79. package/dist/helpers/memoize.mjs +38 -0
  80. package/dist/helpers/memoize.mjs.map +1 -0
  81. package/dist/helpers/requireTamaguiCore.mjs +34 -0
  82. package/dist/helpers/requireTamaguiCore.mjs.map +1 -0
  83. package/dist/index.mjs +41 -0
  84. package/dist/index.mjs.map +1 -0
  85. package/dist/registerRequire.mjs +107 -0
  86. package/dist/registerRequire.mjs.map +1 -0
  87. package/dist/server.mjs +76 -0
  88. package/dist/server.mjs.map +1 -0
  89. package/dist/setup.mjs +2 -0
  90. package/dist/setup.mjs.map +1 -0
  91. package/dist/{types.native.js → types.mjs} +8 -6
  92. package/dist/types.mjs.map +1 -0
  93. package/package.json +19 -21
  94. package/dist/check-dep-versions.native.js +0 -602
  95. package/dist/check-dep-versions.native.js.map +0 -6
  96. package/dist/checkDeps.native.js +0 -34
  97. package/dist/checkDeps.native.js.map +0 -6
  98. package/dist/constants.native.js +0 -45
  99. package/dist/constants.native.js.map +0 -6
  100. package/dist/exports.native.js +0 -52
  101. package/dist/exports.native.js.map +0 -6
  102. package/dist/extractor/accessSafe.native.js +0 -48
  103. package/dist/extractor/accessSafe.native.js.map +0 -6
  104. package/dist/extractor/babelParse.native.js +0 -62
  105. package/dist/extractor/babelParse.native.js.map +0 -6
  106. package/dist/extractor/bundle.native.js +0 -168
  107. package/dist/extractor/bundle.native.js.map +0 -6
  108. package/dist/extractor/bundleConfig.native.js +0 -394
  109. package/dist/extractor/bundleConfig.native.js.map +0 -6
  110. package/dist/extractor/concatClassName.native.js +0 -69
  111. package/dist/extractor/concatClassName.native.js.map +0 -6
  112. package/dist/extractor/createEvaluator.native.js +0 -63
  113. package/dist/extractor/createEvaluator.native.js.map +0 -6
  114. package/dist/extractor/createExtractor.native.js +0 -1229
  115. package/dist/extractor/createExtractor.native.js.map +0 -6
  116. package/dist/extractor/createLogger.native.js +0 -35
  117. package/dist/extractor/createLogger.native.js.map +0 -6
  118. package/dist/extractor/errors.native.js +0 -119
  119. package/dist/extractor/errors.native.js.map +0 -6
  120. package/dist/extractor/esbuildAliasPlugin.native.js +0 -52
  121. package/dist/extractor/esbuildAliasPlugin.native.js.map +0 -6
  122. package/dist/extractor/esbuildTsconfigPaths.native.js +0 -79
  123. package/dist/extractor/esbuildTsconfigPaths.native.js.map +0 -6
  124. package/dist/extractor/evaluateAstNode.native.js +0 -98
  125. package/dist/extractor/evaluateAstNode.native.js.map +0 -6
  126. package/dist/extractor/extractHelpers.native.js +0 -183
  127. package/dist/extractor/extractHelpers.native.js.map +0 -6
  128. package/dist/extractor/extractMediaStyle.native.js +0 -138
  129. package/dist/extractor/extractMediaStyle.native.js.map +0 -6
  130. package/dist/extractor/extractToClassNames.native.js +0 -332
  131. package/dist/extractor/extractToClassNames.native.js.map +0 -6
  132. package/dist/extractor/extractToNative.native.js +0 -276
  133. package/dist/extractor/extractToNative.native.js.map +0 -6
  134. package/dist/extractor/findTopmostFunction.native.js +0 -37
  135. package/dist/extractor/findTopmostFunction.native.js.map +0 -6
  136. package/dist/extractor/generatedUid.native.js.map +0 -6
  137. package/dist/extractor/getPrefixLogs.native.js +0 -30
  138. package/dist/extractor/getPrefixLogs.native.js.map +0 -6
  139. package/dist/extractor/getPropValueFromAttributes.native.js +0 -68
  140. package/dist/extractor/getPropValueFromAttributes.native.js.map +0 -6
  141. package/dist/extractor/getSourceModule.native.js +0 -80
  142. package/dist/extractor/getSourceModule.native.js.map +0 -6
  143. package/dist/extractor/getStaticBindingsForScope.native.js +0 -183
  144. package/dist/extractor/getStaticBindingsForScope.native.js.map +0 -6
  145. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.native.js +0 -37
  146. package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.native.js.map +0 -6
  147. package/dist/extractor/literalToAst.native.js +0 -106
  148. package/dist/extractor/literalToAst.native.js.map +0 -6
  149. package/dist/extractor/loadFile.native.js +0 -21
  150. package/dist/extractor/loadFile.native.js.map +0 -6
  151. package/dist/extractor/loadTamagui.native.js +0 -314
  152. package/dist/extractor/loadTamagui.native.js.map +0 -6
  153. package/dist/extractor/logLines.native.js +0 -53
  154. package/dist/extractor/logLines.native.js.map +0 -6
  155. package/dist/extractor/normalizeTernaries.native.js.map +0 -6
  156. package/dist/extractor/propsToFontFamilyCache.native.js +0 -40
  157. package/dist/extractor/propsToFontFamilyCache.native.js.map +0 -6
  158. package/dist/extractor/regenerateConfig.native.js +0 -148
  159. package/dist/extractor/regenerateConfig.native.js.map +0 -6
  160. package/dist/extractor/removeUnusedHooks.native.js +0 -111
  161. package/dist/extractor/removeUnusedHooks.native.js.map +0 -6
  162. package/dist/extractor/timer.native.js +0 -44
  163. package/dist/extractor/timer.native.js.map +0 -6
  164. package/dist/extractor/validHTMLAttributes.native.js.map +0 -6
  165. package/dist/extractor/watchTamaguiConfig.native.js +0 -60
  166. package/dist/extractor/watchTamaguiConfig.native.js.map +0 -6
  167. package/dist/getPragmaOptions.native.js +0 -62
  168. package/dist/getPragmaOptions.native.js.map +0 -6
  169. package/dist/helpers/memoize.native.js +0 -40
  170. package/dist/helpers/memoize.native.js.map +0 -6
  171. package/dist/helpers/requireTamaguiCore.native.js +0 -34
  172. package/dist/helpers/requireTamaguiCore.native.js.map +0 -6
  173. package/dist/index.native.js +0 -35
  174. package/dist/index.native.js.map +0 -6
  175. package/dist/registerRequire.native.js +0 -124
  176. package/dist/registerRequire.native.js.map +0 -6
  177. package/dist/server.native.js +0 -70
  178. package/dist/server.native.js.map +0 -6
  179. package/dist/setup.native.js +0 -2
  180. package/dist/setup.native.js.map +0 -6
  181. package/dist/types.native.js.map +0 -6
@@ -0,0 +1,976 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var createExtractor_exports = {};
33
+ __export(createExtractor_exports, {
34
+ createExtractor: () => createExtractor
35
+ });
36
+ module.exports = __toCommonJS(createExtractor_exports);
37
+ var import_traverse = __toESM(require("@babel/traverse")),
38
+ t = __toESM(require("@babel/types")),
39
+ import_cli_color = require("@tamagui/cli-color"),
40
+ reactNativeWebInternals = __toESM(require("@tamagui/react-native-web-internals")),
41
+ import_web = require("@tamagui/web"),
42
+ import_node_path = require("node:path"),
43
+ import_constants = require("../constants.mjs"),
44
+ import_requireTamaguiCore = require("../helpers/requireTamaguiCore.mjs"),
45
+ import_createEvaluator = require("./createEvaluator.mjs"),
46
+ import_evaluateAstNode = require("./evaluateAstNode.mjs"),
47
+ import_extractHelpers = require("./extractHelpers.mjs"),
48
+ import_findTopmostFunction = require("./findTopmostFunction.mjs"),
49
+ import_getStaticBindingsForScope = require("./getStaticBindingsForScope.mjs"),
50
+ import_literalToAst = require("./literalToAst.mjs"),
51
+ import_loadTamagui = require("./loadTamagui.mjs"),
52
+ import_logLines = require("./logLines.mjs"),
53
+ import_normalizeTernaries = require("./normalizeTernaries.mjs"),
54
+ import_propsToFontFamilyCache = require("./propsToFontFamilyCache.mjs"),
55
+ import_timer = require("./timer.mjs"),
56
+ import_validHTMLAttributes = require("./validHTMLAttributes.mjs"),
57
+ import_errors = require("./errors.mjs");
58
+ const UNTOUCHED_PROPS = {
59
+ key: !0,
60
+ style: !0,
61
+ className: !0
62
+ },
63
+ createTernary = x => x;
64
+ let hasLoggedBaseInfo = !1;
65
+ function isFullyDisabled(props) {
66
+ return props.disableExtraction && props.disableDebugAttr;
67
+ }
68
+ function createExtractor({
69
+ logger = console,
70
+ platform = "web"
71
+ } = {
72
+ logger: console
73
+ }) {
74
+ const INLINE_EXTRACTABLE = {
75
+ ref: "ref",
76
+ key: "key",
77
+ ...(platform === "web" && {
78
+ onPress: "onClick",
79
+ onHoverIn: "onMouseEnter",
80
+ onHoverOut: "onMouseLeave",
81
+ onPressIn: "onMouseDown",
82
+ onPressOut: "onMouseUp"
83
+ })
84
+ },
85
+ componentState = {
86
+ focus: !1,
87
+ focusVisible: !1,
88
+ focusWithin: !1,
89
+ hover: !1,
90
+ unmounted: !0,
91
+ press: !1,
92
+ pressIn: !1,
93
+ disabled: !1
94
+ },
95
+ styleProps = {
96
+ resolveValues: "variable",
97
+ noClass: !1,
98
+ isAnimated: !1
99
+ },
100
+ shouldAddDebugProp =
101
+ // really basic disable this for next.js because it messes with ssr
102
+ !process.env.npm_package_dependencies_next && !0 && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.IDENTIFY_TAGS);
103
+ let projectInfo = null;
104
+ function loadSync(props) {
105
+ return isFullyDisabled(props) ? null : projectInfo ||= (0, import_loadTamagui.loadTamaguiSync)(props);
106
+ }
107
+ async function load(props) {
108
+ return isFullyDisabled(props) ? null : projectInfo ||= await (0, import_loadTamagui.loadTamagui)(props);
109
+ }
110
+ return {
111
+ options: {
112
+ logger
113
+ },
114
+ cleanupBeforeExit: import_getStaticBindingsForScope.cleanupBeforeExit,
115
+ loadTamagui: load,
116
+ loadTamaguiSync: loadSync,
117
+ getTamagui() {
118
+ return projectInfo?.tamaguiConfig;
119
+ },
120
+ parseSync: (f, props) => {
121
+ globalThis.expo ||= {};
122
+ const projectInfo2 = loadSync(props);
123
+ return parseWithConfig(projectInfo2 || {}, f, props);
124
+ },
125
+ parse: async (f, props) => {
126
+ globalThis.expo ||= {};
127
+ const projectInfo2 = await load(props);
128
+ return parseWithConfig(projectInfo2 || {}, f, props);
129
+ }
130
+ };
131
+ function parseWithConfig({
132
+ components,
133
+ tamaguiConfig
134
+ }, fileOrPath, options) {
135
+ const {
136
+ config = "tamagui.config.ts",
137
+ importsWhitelist = ["constants.js"],
138
+ evaluateVars = !0,
139
+ sourcePath = "",
140
+ onExtractTag,
141
+ onStyledDefinitionRule,
142
+ getFlattenedNode,
143
+ disable,
144
+ disableExtraction,
145
+ disableExtractVariables,
146
+ disableDebugAttr,
147
+ enableDynamicEvaluation = !1,
148
+ includeExtensions = [".ts", ".tsx", ".jsx"],
149
+ extractStyledDefinitions = !1,
150
+ prefixLogs,
151
+ excludeProps,
152
+ platform: platform2,
153
+ ...restProps
154
+ } = options;
155
+ if (sourcePath.includes(".tamagui-dynamic-eval")) return null;
156
+ const {
157
+ normalizeStyle,
158
+ getSplitStyles,
159
+ mediaQueryConfig,
160
+ propMapper,
161
+ proxyThemeVariables,
162
+ pseudoDescriptors
163
+ } = (0, import_requireTamaguiCore.requireTamaguiCore)(platform2);
164
+ let shouldPrintDebug = options.shouldPrintDebug || !1;
165
+ if (disable === !0 || Array.isArray(disable) && disable.includes(sourcePath)) return null;
166
+ if (!isFullyDisabled(options) && !components) throw new Error("Must provide components");
167
+ if (sourcePath && includeExtensions && !includeExtensions.some(ext => sourcePath.endsWith(ext))) return shouldPrintDebug && logger.info(`Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(", ")}`), null;
168
+ function isValidStyleKey(name, staticConfig) {
169
+ if (!projectInfo) throw new Error("Tamagui extractor not loaded yet");
170
+ return platform2 === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)] ? !1 : !!(staticConfig.validStyles?.[name] || pseudoDescriptors[name] ||
171
+ // don't disable variants or else you lose many things flattening
172
+ staticConfig.variants?.[name] || projectInfo?.tamaguiConfig?.shorthands[name] || name[0] === "$" && mediaQueryConfig[name.slice(1)]);
173
+ }
174
+ const isTargetingHTML = platform2 === "web",
175
+ ogDebug = shouldPrintDebug,
176
+ tm = (0, import_timer.timer)(),
177
+ propsWithFileInfo = {
178
+ ...options,
179
+ sourcePath,
180
+ allLoadedComponents: components ? [...components] : []
181
+ };
182
+ hasLoggedBaseInfo || (hasLoggedBaseInfo = !0, shouldPrintDebug && logger.info(["loaded components:", propsWithFileInfo.allLoadedComponents.map(comp => Object.keys(comp.nameToInfo).join(", ")).join(", ")].join(" ")), process.env.DEBUG?.startsWith("tamagui") && logger.info(["loaded:", propsWithFileInfo.allLoadedComponents.map(x => x.moduleName)].join(`
183
+ `))), tm.mark("load-tamagui", !!shouldPrintDebug), isFullyDisabled(options) || tamaguiConfig?.themes || (console.error(`\u26D4\uFE0F Error: Missing "themes" in your tamagui.config file:
184
+
185
+ You may not need the compiler! Remember you can run Tamagui with no configuration at all.
186
+
187
+ You may have not "export default" your config (you can also "export const config").
188
+
189
+ Or this may be due to duplicated dependency versions:
190
+ - try out https://github.com/bmish/check-dependency-version-consistency to see if there are mis-matches.
191
+ - or search your lockfile for mis-matches.
192
+ `), console.info(" Got config:", tamaguiConfig), process.exit(0));
193
+ const firstThemeName = Object.keys(tamaguiConfig?.themes || {})[0],
194
+ firstTheme = tamaguiConfig?.themes[firstThemeName] || {};
195
+ if (!firstTheme || typeof firstTheme != "object") {
196
+ const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`;
197
+ throw console.info(err, "Got config:", tamaguiConfig), console.info("Looking for theme:", firstThemeName), new Error(err);
198
+ }
199
+ const proxiedTheme = proxyThemeVariables(firstTheme),
200
+ themeAccessListeners = /* @__PURE__ */new Set(),
201
+ defaultTheme = new Proxy(proxiedTheme, {
202
+ get(target, key) {
203
+ return Reflect.has(target, key) && themeAccessListeners.forEach(cb => cb(String(key))), Reflect.get(target, key);
204
+ }
205
+ }),
206
+ body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
207
+ isFullyDisabled(options) || Object.keys(components || []).length === 0 && (console.warn("Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)"), process.env.DEBUG === "tamagui" && console.info("components", Object.keys(components || []), components)), shouldPrintDebug === "verbose" && (logger.info(`allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map(k => k.moduleName).join(", ")}`), logger.info(`valid import paths: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))}`));
208
+ let doesUseValidImport = !1,
209
+ hasImportedTheme = !1;
210
+ const importDeclarations = [];
211
+ for (const bodyPath of body) {
212
+ if (bodyPath.type !== "ImportDeclaration") continue;
213
+ const node = "node" in bodyPath ? bodyPath.node : bodyPath,
214
+ moduleName = node.source.value,
215
+ valid = (0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName);
216
+ if (valid && importDeclarations.push(node), shouldPrintDebug === "verbose" && logger.info(` - import via ${moduleName} ${valid}`), extractStyledDefinitions && valid && node.specifiers.some(specifier => specifier.local.name === "styled")) {
217
+ doesUseValidImport = !0;
218
+ break;
219
+ }
220
+ if (valid) {
221
+ const names = node.specifiers.map(specifier => specifier.local.name),
222
+ isValidComponent = names.some(name => !!(0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, name));
223
+ if (shouldPrintDebug === "verbose" && logger.info(` - import ${isValidComponent ? "\u2705" : "\u21E3"} - ${names.join(", ")} via package '${moduleName}' - (valid: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))})`), isValidComponent) {
224
+ doesUseValidImport = !0;
225
+ break;
226
+ }
227
+ }
228
+ }
229
+ if (shouldPrintDebug && logger.info(`${JSON.stringify({
230
+ doesUseValidImport,
231
+ hasImportedTheme
232
+ }, null, 2)}
233
+ `), !doesUseValidImport) return null;
234
+ function getValidImportedComponent(componentName) {
235
+ const importDeclaration = importDeclarations.find(dec => dec.specifiers.some(spec => spec.local.name === componentName));
236
+ return importDeclaration ? (0, import_extractHelpers.getValidImport)(propsWithFileInfo, importDeclaration.source.value, componentName) : null;
237
+ }
238
+ tm.mark("import-check", !!shouldPrintDebug);
239
+ let couldntParse = !1;
240
+ const modifiedComponents = /* @__PURE__ */new Set(),
241
+ bindingCache = {},
242
+ callTraverse = a => fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a),
243
+ shouldDisableExtraction = disableExtraction === !0 || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
244
+ let programPath = null;
245
+ const res = {
246
+ styled: 0,
247
+ flattened: 0,
248
+ optimized: 0,
249
+ modified: 0,
250
+ found: 0
251
+ },
252
+ version = `${Math.random()}`;
253
+ return callTraverse({
254
+ // @ts-ignore
255
+ Program: {
256
+ enter(path) {
257
+ programPath = path;
258
+ }
259
+ },
260
+ // styled() calls
261
+ CallExpression(path) {
262
+ if (disable || shouldDisableExtraction || extractStyledDefinitions === !1 || !t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") return;
263
+ const variableName = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown",
264
+ parentNode = path.node.arguments[0];
265
+ if (!t.isIdentifier(parentNode)) return;
266
+ const parentName = parentNode.name,
267
+ definition = path.node.arguments[1];
268
+ if (!parentName || !definition || !t.isObjectExpression(definition)) return;
269
+ let Component = getValidImportedComponent(variableName);
270
+ if (!Component) {
271
+ if (enableDynamicEvaluation !== !0) return;
272
+ try {
273
+ shouldPrintDebug && logger.info(`Unknown component: ${variableName} = styled(${parentName}) attempting dynamic load: ${sourcePath}`);
274
+ const out2 = (0, import_loadTamagui.loadTamaguiSync)({
275
+ forceExports: !0,
276
+ components: [sourcePath],
277
+ cacheKey: version
278
+ });
279
+ if (!out2?.components) {
280
+ shouldPrintDebug && logger.info(`Couldn't load, got ${out2}`);
281
+ return;
282
+ }
283
+ if (propsWithFileInfo.allLoadedComponents = [...propsWithFileInfo.allLoadedComponents, ...out2.components], Component = out2.components.flatMap(x => x.nameToInfo[variableName] ?? [])[0], !out2.cached) {
284
+ const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
285
+ foundNames && (0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Tamagui found dynamic components: ${foundNames}`);
286
+ }
287
+ } catch {
288
+ shouldPrintDebug && logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=tamagui for more)`);
289
+ }
290
+ }
291
+ if (!Component) {
292
+ shouldPrintDebug && logger.info(" No component found");
293
+ return;
294
+ }
295
+ const componentSkipProps = /* @__PURE__ */new Set([...(Component.staticConfig.inlineWhenUnflattened || []), ...(Component.staticConfig.inlineProps || []),
296
+ // for now skip variants, will return to them
297
+ "variants", "defaultVariants",
298
+ // skip fontFamily its basically a "variant", important for theme use to be value always
299
+ "fontFamily", "name", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle", "hoverStyle", "pressStyle"]),
300
+ skipped = /* @__PURE__ */new Set(),
301
+ styles = {},
302
+ staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug),
303
+ attemptEval = evaluateVars ? (0, import_createEvaluator.createEvaluator)({
304
+ props: propsWithFileInfo,
305
+ staticNamespace,
306
+ sourcePath,
307
+ shouldPrintDebug
308
+ }) : import_evaluateAstNode.evaluateAstNode,
309
+ attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
310
+ for (const property of definition.properties) {
311
+ if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) ||
312
+ // TODO make pseudos and variants work
313
+ // skip pseudos
314
+ pseudoDescriptors[property.key.name] ||
315
+ // skip variants
316
+ Component.staticConfig.variants?.[property.key.name] || componentSkipProps.has(property.key.name)) {
317
+ skipped.add(property);
318
+ continue;
319
+ }
320
+ const out2 = attemptEvalSafe(property.value);
321
+ out2 === import_constants.FAILED_EVAL ? skipped.add(property) : styles[property.key.name] = out2;
322
+ }
323
+ const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, "", componentState, styleProps, void 0, void 0, void 0, void 0, !1, shouldPrintDebug),
324
+ classNames = {
325
+ ...out.classNames
326
+ };
327
+ if (shouldPrintDebug && logger.info([`Extracted styled(${variableName})
328
+ `, JSON.stringify(styles, null, 2), `
329
+ classNames:`, JSON.stringify(classNames, null, 2), `
330
+ rulesToInsert:`, out.rulesToInsert].join(" ")), definition.properties = definition.properties.map(prop => {
331
+ if (skipped.has(prop) || !t.isObjectProperty(prop) || !t.isIdentifier(prop.key)) return prop;
332
+ const key = prop.key.name,
333
+ value = classNames[key];
334
+ return value ? t.objectProperty(t.stringLiteral(key), t.stringLiteral(value)) : prop;
335
+ }), out.rulesToInsert) for (const key in out.rulesToInsert) {
336
+ const styleObject = out.rulesToInsert[key];
337
+ onStyledDefinitionRule?.(styleObject[import_web.StyleObjectIdentifier], styleObject[import_web.StyleObjectRules]);
338
+ }
339
+ res.styled++, shouldPrintDebug && logger.info(`Extracted styled(${variableName})`);
340
+ },
341
+ JSXElement(traversePath) {
342
+ tm.mark("jsx-element", !!shouldPrintDebug);
343
+ const node = traversePath.node.openingElement,
344
+ ogAttributes = node.attributes.map(attr => ({
345
+ ...attr
346
+ })),
347
+ componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope),
348
+ closingElement = traversePath.node.closingElement;
349
+ if (closingElement && t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
350
+ shouldPrintDebug && logger.info(" skip non-identifier element");
351
+ return;
352
+ }
353
+ const binding = traversePath.scope.getBinding(node.name.name);
354
+ let moduleName = "";
355
+ if (binding && t.isImportDeclaration(binding.path.parent) && (moduleName = binding.path.parent.source.value, !(0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, binding.identifier.name))) {
356
+ shouldPrintDebug && logger.info(` - Binding in component ${componentName} not valid import: "${binding.identifier.name}" isn't in ${moduleName}
357
+ `);
358
+ return;
359
+ }
360
+ const component = (0, import_extractHelpers.getValidComponent)(propsWithFileInfo, moduleName, node.name.name);
361
+ if (!component || !component.staticConfig) {
362
+ shouldPrintDebug && logger.info(`
363
+ - No Tamagui conf for: ${node.name.name}
364
+ `);
365
+ return;
366
+ }
367
+ const originalNodeName = node.name.name;
368
+ res.found++;
369
+ const filePath = `./${(0, import_node_path.relative)(process.cwd(), sourcePath)}`,
370
+ lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "",
371
+ codePosition = `${filePath}:${lineNumbers}`,
372
+ debugPropValue = node.attributes.filter(n => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map(n => n.value === null ? !0 : t.isStringLiteral(n.value) ? n.value.value : !1)[0];
373
+ if (debugPropValue && (shouldPrintDebug = debugPropValue), shouldPrintDebug && (logger.info(`\x1B[33m\x1B[0m ${componentName} | ${codePosition} -------------------`), logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "))), shouldAddDebugProp && !disableDebugAttr && (res.modified++, node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name))), componentName && node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName))), node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-at"), t.stringLiteral(`${(0, import_node_path.basename)(filePath)}:${lineNumbers}`)))), shouldDisableExtraction) {
374
+ shouldPrintDebug === "verbose" && logger.info(` \u274C Extraction disabled: ${JSON.stringify(disableExtraction)}
375
+ `);
376
+ return;
377
+ }
378
+ try {
379
+ let evaluateAttribute = function (path) {
380
+ const attribute = path.node,
381
+ attr = {
382
+ type: "attr",
383
+ value: attribute
384
+ };
385
+ if (t.isJSXSpreadAttribute(attribute)) {
386
+ const arg = attribute.argument,
387
+ conditional = t.isConditionalExpression(arg) ?
388
+ // <YStack {...isSmall ? { color: 'red } : { color: 'blue }}
389
+ [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ?
390
+ // <YStack {...isSmall && { color: 'red }}
391
+ [arg.left, arg.right, null] : null;
392
+ if (conditional) {
393
+ const [test, alt, cons] = conditional;
394
+ if (!test) throw new Error("no test");
395
+ return [alt, cons].some(side => side && !isStaticObject(side)) ? (shouldPrintDebug && logger.info(`not extractable ${alt} ${cons}`), attr) : [...(flattenNestedTernaries(test, alt) || []), ...(cons && flattenNestedTernaries(t.unaryExpression("!", test), cons) || [])].map(ternary => ({
396
+ type: "ternary",
397
+ value: ternary
398
+ }));
399
+ }
400
+ }
401
+ if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name != "string") return shouldPrintDebug && logger.info(" ! inlining, spread attr"), inlined.set(`${Math.random()}`, "spread"), attr;
402
+ const name = attribute.name.name;
403
+ if (name === "style") return shouldDeopt = !0, null;
404
+ if (excludeProps?.has(name)) return shouldPrintDebug && logger.info([" excluding prop", name].join(" ")), null;
405
+ if (inlineProps.has(name)) return inlined.set(name, name), shouldPrintDebug && logger.info([" ! inlining, inline prop", name].join(" ")), attr;
406
+ if (UNTOUCHED_PROPS[name]) return attr;
407
+ if (INLINE_EXTRACTABLE[name]) return inlined.set(name, INLINE_EXTRACTABLE[name]), attr;
408
+ if (name.startsWith("data-")) return attr;
409
+ if ((name === "enterStyle" || name === "exitStyle") && t.isJSXExpressionContainer(attribute?.value)) return shouldDeopt = !0, attr;
410
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
411
+ const shortname = name.slice(1);
412
+ if (mediaQueryConfig[shortname]) {
413
+ const expression = attribute.value.expression;
414
+ if (!t.isJSXEmptyExpression(expression)) {
415
+ const ternaries2 = flattenNestedTernaries(t.stringLiteral(shortname), expression, {
416
+ inlineMediaQuery: shortname
417
+ });
418
+ if (ternaries2) return ternaries2.map(value2 => ({
419
+ type: "ternary",
420
+ value: value2
421
+ }));
422
+ }
423
+ }
424
+ }
425
+ const [value, valuePath] = t.isJSXExpressionContainer(attribute?.value) ? [attribute.value.expression, path.get("value")] : [attribute.value, path.get("value")],
426
+ remove = () => {
427
+ Array.isArray(valuePath) ? valuePath.map(p => p.remove()) : valuePath.remove();
428
+ };
429
+ if (name === "ref") return shouldPrintDebug && logger.info([" ! inlining, ref", name].join(" ")), inlined.set("ref", "ref"), attr;
430
+ if (name === "tag") return {
431
+ type: "attr",
432
+ value: path.node
433
+ };
434
+ if (disableExtractVariables === !0 && value && value.type === "StringLiteral" && value.value[0] === "$") return shouldPrintDebug && logger.info([` ! inlining, native disable extract: ${name} =`, value.value].join(" ")), inlined.set(name, !0), attr;
435
+ if (name === "theme") return inlined.set("theme", attr.value), attr;
436
+ const styleValue = attemptEvalSafe(value);
437
+ if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
438
+ let out = null;
439
+ propMapper(name, styleValue, propMapperStyleState, !1, (key, val) => {
440
+ out ||= {}, out[key] = val;
441
+ }), out && isTargetingHTML && (out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out), delete out.className);
442
+ let didInline = !1;
443
+ const attributes = Object.keys(out).map(key => {
444
+ const val = out[key];
445
+ return isValidStyleKey(key, staticConfig) ? {
446
+ type: "style",
447
+ value: {
448
+ [key]: styleValue
449
+ },
450
+ name: key,
451
+ attr: path.node
452
+ } : import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") ||
453
+ // this is debug stuff added by vite / new jsx transform
454
+ key === "__source" || key === "__self" ? attr : (shouldPrintDebug && logger.info(" ! inlining, non-static " + key), didInline = !0, inlined.set(key, val), val);
455
+ });
456
+ return didInline ? (shouldPrintDebug && logger.info(` bailing flattening due to attributes ${attributes.map(x => x.toString())}`), attr) : attributes;
457
+ }
458
+ if (styleValue !== import_constants.FAILED_EVAL) return inlineWhenUnflattened.has(name) && (inlineWhenUnflattenedOGVals[name] = {
459
+ styleValue,
460
+ attr
461
+ }), isValidStyleKey(name, staticConfig) ? (shouldPrintDebug && logger.info(` style: ${name} = ${JSON.stringify(styleValue)}`), name in defaultProps || hasSetOptimized || (res.optimized++, hasSetOptimized = !0), {
462
+ type: "style",
463
+ value: {
464
+ [name]: styleValue
465
+ },
466
+ name,
467
+ attr: path.node
468
+ }) : (variants[name] && variantValues.set(name, styleValue), inlined.set(name, !0), attr);
469
+ if (t.isBinaryExpression(value)) {
470
+ shouldPrintDebug && logger.info(` binary expression ${name} = ${value}`);
471
+ const {
472
+ operator,
473
+ left,
474
+ right
475
+ } = value,
476
+ lVal = attemptEvalSafe(left),
477
+ rVal = attemptEvalSafe(right);
478
+ if (shouldPrintDebug && logger.info(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`), lVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
479
+ const ternary = addBinaryConditional(operator, left, right);
480
+ if (ternary) return ternary;
481
+ }
482
+ if (rVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(left)) {
483
+ const ternary = addBinaryConditional(operator, right, left);
484
+ if (ternary) return ternary;
485
+ }
486
+ return shouldPrintDebug && logger.info(" evalBinaryExpression cant extract"), inlined.set(name, !0), attr;
487
+ }
488
+ const staticConditional = getStaticConditional(value);
489
+ if (staticConditional) return shouldPrintDebug === "verbose" && logger.info(` static conditional ${name} ${value}`), {
490
+ type: "ternary",
491
+ value: staticConditional
492
+ };
493
+ const staticLogical = getStaticLogical(value);
494
+ if (staticLogical) return shouldPrintDebug === "verbose" && logger.info(` static ternary ${name} = ${value}`), {
495
+ type: "ternary",
496
+ value: staticLogical
497
+ };
498
+ return inlined.set(name, !0), shouldPrintDebug && logger.info(` ! inline no match ${name} ${value}`), attr;
499
+ function addBinaryConditional(operator, staticExpr, cond) {
500
+ if (getStaticConditional(cond)) {
501
+ const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate)),
502
+ cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
503
+ return shouldPrintDebug && logger.info([" binaryConditional", cond.test, cons, alt].join(" ")), {
504
+ type: "ternary",
505
+ value: {
506
+ test: cond.test,
507
+ remove,
508
+ alternate: {
509
+ [name]: alt
510
+ },
511
+ consequent: {
512
+ [name]: cons
513
+ }
514
+ }
515
+ };
516
+ }
517
+ return null;
518
+ }
519
+ function getStaticConditional(value2) {
520
+ if (t.isConditionalExpression(value2)) try {
521
+ const aVal = attemptEval(value2.alternate),
522
+ cVal = attemptEval(value2.consequent);
523
+ if (shouldPrintDebug) {
524
+ const type = value2.test.type;
525
+ logger.info([" static ternary", type, cVal, aVal].join(" "));
526
+ }
527
+ return {
528
+ test: value2.test,
529
+ remove,
530
+ consequent: {
531
+ [name]: cVal
532
+ },
533
+ alternate: {
534
+ [name]: aVal
535
+ }
536
+ };
537
+ } catch (err) {
538
+ shouldPrintDebug && logger.info([" cant eval ternary", err.message].join(" "));
539
+ }
540
+ return null;
541
+ }
542
+ function getStaticLogical(value2) {
543
+ if (t.isLogicalExpression(value2) && value2.operator === "&&") try {
544
+ const val = attemptEval(value2.right);
545
+ return shouldPrintDebug && logger.info([" staticLogical", value2.left, name, val].join(" ")), {
546
+ test: value2.left,
547
+ remove,
548
+ consequent: {
549
+ [name]: val
550
+ },
551
+ alternate: null
552
+ };
553
+ } catch (err) {
554
+ shouldPrintDebug && logger.info([" cant static eval logical", err].join(" "));
555
+ }
556
+ return null;
557
+ }
558
+ },
559
+ isStaticObject = function (obj) {
560
+ return t.isObjectExpression(obj) && obj.properties.every(prop => {
561
+ if (!t.isObjectProperty(prop)) return !1;
562
+ const propName = prop.key.name;
563
+ return !isValidStyleKey(propName, staticConfig) && propName !== "tag" ? (shouldPrintDebug && logger.info([" not a valid style prop!", propName].join(" ")), !1) : !0;
564
+ });
565
+ },
566
+ flattenNestedTernaries = function (test, side, ternaryPartial = {}) {
567
+ if (!side) return null;
568
+ if (!isStaticObject(side)) throw new Error("not extractable");
569
+ return side.properties.flatMap(property => {
570
+ if (!t.isObjectProperty(property)) throw new Error("expected object property");
571
+ if (t.isConditionalExpression(property.value)) {
572
+ const [truthy, falsy] = [t.objectExpression([t.objectProperty(property.key, property.value.consequent)]), t.objectExpression([t.objectProperty(property.key, property.value.alternate)])].map(x => attemptEval(x));
573
+ return [createTernary({
574
+ remove() {},
575
+ ...ternaryPartial,
576
+ test: t.logicalExpression("&&", test, property.value.test),
577
+ consequent: truthy,
578
+ alternate: null
579
+ }), createTernary({
580
+ ...ternaryPartial,
581
+ test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
582
+ consequent: falsy,
583
+ alternate: null,
584
+ remove() {}
585
+ })];
586
+ }
587
+ const obj = t.objectExpression([t.objectProperty(property.key, property.value)]),
588
+ consequent = attemptEval(obj);
589
+ return createTernary({
590
+ remove() {},
591
+ ...ternaryPartial,
592
+ test,
593
+ consequent,
594
+ alternate: null
595
+ });
596
+ });
597
+ },
598
+ mergeToEnd = function (obj, key, val) {
599
+ key in obj && delete obj[key], obj[key] = val;
600
+ },
601
+ normalizeStyleWithoutVariants = function (style) {
602
+ let res2 = {};
603
+ for (const key in style) if (staticConfig.variants && key in staticConfig.variants) mergeToEnd(res2, key, style[key]);else {
604
+ const expanded = normalizeStyle({
605
+ [key]: style[key]
606
+ }, !0);
607
+ for (const key2 in expanded) mergeToEnd(res2, key2, expanded[key2]);
608
+ }
609
+ return res2;
610
+ },
611
+ mergeStyles = function (prev2, next) {
612
+ for (const key in next) pseudoDescriptors[key] ? (prev2[key] = prev2[key] || {}, Object.assign(prev2[key], next[key])) : mergeToEnd(prev2, key, next[key]);
613
+ };
614
+ const {
615
+ staticConfig
616
+ } = component,
617
+ defaultProps = {
618
+ ...(staticConfig.defaultProps || {})
619
+ },
620
+ variants = staticConfig.variants || {},
621
+ isTextView = staticConfig.isText || !1,
622
+ validStyles = staticConfig?.validStyles ?? {};
623
+ let tagName = defaultProps.tag ?? (isTextView ? "span" : "div");
624
+ traversePath.get("openingElement").get("attributes").forEach(path => {
625
+ const attr = path.node;
626
+ if (t.isJSXSpreadAttribute(attr) || attr.name.name !== "tag") return;
627
+ const val = attr.value;
628
+ t.isStringLiteral(val) && (tagName = val.value);
629
+ }), shouldPrintDebug === "verbose" && console.info(` Start tag ${tagName}`);
630
+ const flatNodeName = getFlattenedNode?.({
631
+ isTextView,
632
+ tag: tagName
633
+ }),
634
+ inlineProps = /* @__PURE__ */new Set([
635
+ // adding some always inline props
636
+ "dataSet", ...(restProps.inlineProps || []), ...(staticConfig.inlineProps || [])]),
637
+ deoptProps = /* @__PURE__ */new Set([
638
+ // always de-opt animation these
639
+ "animation", "animateOnly", "animatePresence", "disableOptimization", ...(isTargetingHTML ? [] : ["pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"]),
640
+ // when using a non-CSS driver, de-opt on enterStyle/exitStyle
641
+ ...(tamaguiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]),
642
+ inlineWhenUnflattened = /* @__PURE__ */new Set([...(staticConfig.inlineWhenUnflattened || [])]),
643
+ staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug),
644
+ attemptEval = evaluateVars ? (0, import_createEvaluator.createEvaluator)({
645
+ props: propsWithFileInfo,
646
+ staticNamespace,
647
+ sourcePath,
648
+ traversePath,
649
+ shouldPrintDebug
650
+ }) : import_evaluateAstNode.evaluateAstNode,
651
+ attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
652
+ if (shouldPrintDebug && logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`), couldntParse) return;
653
+ tm.mark("jsx-element-flattened", !!shouldPrintDebug);
654
+ let attrs = [],
655
+ shouldDeopt = !1;
656
+ const inlined = /* @__PURE__ */new Map(),
657
+ variantValues = /* @__PURE__ */new Map();
658
+ let hasSetOptimized = !1;
659
+ const inlineWhenUnflattenedOGVals = {},
660
+ propMapperStyleState = {
661
+ staticConfig,
662
+ usedKeys: {},
663
+ classNames: {},
664
+ style: {},
665
+ theme: defaultTheme,
666
+ viewProps: defaultProps,
667
+ conf: tamaguiConfig,
668
+ props: defaultProps,
669
+ componentState,
670
+ styleProps: {
671
+ ...styleProps,
672
+ resolveValues: "auto"
673
+ },
674
+ debug: shouldPrintDebug
675
+ };
676
+ if (attrs = traversePath.get("openingElement").get("attributes").flatMap(path => {
677
+ if (!shouldDeopt) try {
678
+ const res2 = evaluateAttribute(path);
679
+ return res2 || path.remove(), res2;
680
+ } catch (err) {
681
+ return shouldPrintDebug && (logger.info(["Recoverable error extracting attribute", err.message, shouldPrintDebug === "verbose" ? err.stack : ""].join(" ")), shouldPrintDebug === "verbose" && logger.info(`node ${path.node?.type}`)), inlined.set(`${Math.random()}`, "spread"), {
682
+ type: "attr",
683
+ value: path.node
684
+ };
685
+ }
686
+ }).flat(4).filter(import_extractHelpers.isPresent), shouldPrintDebug && logger.info([` - attrs (before):
687
+ `, (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" ")), couldntParse || shouldDeopt) {
688
+ shouldPrintDebug && logger.info([" avoid optimizing:", {
689
+ couldntParse,
690
+ shouldDeopt
691
+ }].join(" ")), node.attributes = ogAttributes;
692
+ return;
693
+ }
694
+ const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
695
+ parentFn && modifiedComponents.add(parentFn);
696
+ const hasSpread = attrs.some(x => x.type === "attr" && t.isJSXSpreadAttribute(x.value)),
697
+ hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every(x => x.type === "JSXText"));
698
+ let themeVal = inlined.get("theme");
699
+ platform2 !== "native" && inlined.delete("theme");
700
+ for (const [key] of [...inlined]) {
701
+ const isStaticObjectVariant = staticConfig.variants?.[key] && variantValues.has(key);
702
+ (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) && inlined.delete(key);
703
+ }
704
+ const canFlattenProps = inlined.size === 0;
705
+ let shouldFlatten = !!(flatNodeName && !shouldDeopt && canFlattenProps && !hasSpread && !staticConfig.isStyledHOC && !staticConfig.isHOC && !staticConfig.isReactNative && staticConfig.neverFlatten !== !0 && (staticConfig.neverFlatten !== "jsx" || hasOnlyStringChildren));
706
+ const usedThemeKeys = /* @__PURE__ */new Set();
707
+ if (themeAccessListeners.add(key => {
708
+ disableExtractVariables && (usedThemeKeys.add(key), shouldFlatten = !1, shouldPrintDebug === "verbose" && logger.info([" ! accessing theme key, avoid flatten", key].join(" ")));
709
+ }), !shouldFlatten) {
710
+ shouldPrintDebug && logger.info(`Deopting ${JSON.stringify({
711
+ shouldFlatten,
712
+ shouldDeopt,
713
+ canFlattenProps,
714
+ hasSpread,
715
+ neverFlatten: staticConfig.neverFlatten
716
+ })}`), node.attributes = ogAttributes;
717
+ return;
718
+ }
719
+ let skipMap = !1;
720
+ const defaultStyleAttrs = Object.keys(defaultProps).flatMap(key => {
721
+ if (skipMap) return [];
722
+ const value = defaultProps[key];
723
+ if (key === "theme" && !themeVal) return platform2 === "native" && (shouldFlatten = !1, skipMap = !0, inlined.set("theme", {
724
+ value: t.stringLiteral(value)
725
+ })), themeVal = {
726
+ value: t.stringLiteral(value)
727
+ }, [];
728
+ if (!isValidStyleKey(key, staticConfig)) return [];
729
+ const name = tamaguiConfig?.shorthands[key] || key;
730
+ if (value === void 0) {
731
+ logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`), shouldDeopt = !0;
732
+ return;
733
+ }
734
+ return name[0] === "$" && mediaQueryConfig[name.slice(1)] ? (defaultProps[key] = void 0, evaluateAttribute({
735
+ node: t.jsxAttribute(t.jsxIdentifier(name), t.jsxExpressionContainer(t.objectExpression(Object.keys(value).filter(k => typeof value[k] < "u").map(k => t.objectProperty(t.identifier(k), (0, import_literalToAst.literalToAst)(value[k]))))))
736
+ })) : {
737
+ type: "style",
738
+ name,
739
+ value: {
740
+ [name]: value
741
+ }
742
+ };
743
+ });
744
+ skipMap || defaultStyleAttrs.length && (attrs = [...defaultStyleAttrs, ...attrs]);
745
+ let ternaries = [];
746
+ attrs = attrs.reduce((out, cur) => {
747
+ const next = attrs[attrs.indexOf(cur) + 1];
748
+ if (cur.type === "ternary" && ternaries.push(cur.value), (!next || next.type !== "ternary") && ternaries.length) {
749
+ const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map(({
750
+ alternate,
751
+ consequent,
752
+ ...rest
753
+ }) => ({
754
+ type: "ternary",
755
+ value: {
756
+ ...rest,
757
+ alternate: alternate || null,
758
+ consequent: consequent || null
759
+ }
760
+ }));
761
+ try {
762
+ return [...out, ...normalized];
763
+ } finally {
764
+ shouldPrintDebug && logger.info(` normalizeTernaries (${ternaries.length} => ${normalized.length})`), ternaries = [];
765
+ }
766
+ }
767
+ return cur.type === "ternary" || out.push(cur), out;
768
+ }, []).flat(), themeVal && (programPath ? (shouldPrintDebug && logger.info([" - wrapping theme", themeVal].join(" ")), attrs = attrs.filter(x => !(x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme")), hasImportedTheme || (hasImportedTheme = !0, programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/web")))), traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]))) : console.warn(`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`)), shouldPrintDebug && logger.info([` - attrs (flattened):
769
+ `, (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
770
+ let foundStaticProps = {};
771
+ for (const key in attrs) {
772
+ const cur = attrs[key];
773
+ if (cur.type === "style") {
774
+ const expanded = normalizeStyleWithoutVariants(cur.value);
775
+ for (const key2 in expanded) mergeToEnd(foundStaticProps, key2, expanded[key2]);
776
+ continue;
777
+ }
778
+ if (cur.type === "attr") {
779
+ if (t.isJSXSpreadAttribute(cur.value) || !t.isJSXIdentifier(cur.value.name)) continue;
780
+ const key2 = cur.value.name.name,
781
+ value = attemptEvalSafe(cur.value.value || t.booleanLiteral(!0));
782
+ value !== import_constants.FAILED_EVAL && mergeToEnd(foundStaticProps, key2, value);
783
+ }
784
+ }
785
+ const completeProps = {};
786
+ for (const key in defaultProps) key in foundStaticProps || (completeProps[key] = defaultProps[key]);
787
+ for (const key in foundStaticProps) completeProps[key] = foundStaticProps[key];
788
+ attrs = attrs.reduce((acc, cur) => {
789
+ if (!cur) return acc;
790
+ if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value) && shouldFlatten) {
791
+ const name = cur.value.name.name;
792
+ if (typeof name == "string") {
793
+ if (name === "tag") return acc;
794
+ if (variants[name] && variantValues.has(name)) {
795
+ const styleState = {
796
+ ...propMapperStyleState,
797
+ props: completeProps
798
+ };
799
+ let out = {};
800
+ if (propMapper(name, variantValues.get(name), styleState, !1, (key2, val) => {
801
+ out[key2] = val;
802
+ }), out && isTargetingHTML) {
803
+ const cn = out.className;
804
+ out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out), out.className = cn;
805
+ }
806
+ shouldPrintDebug && logger.info([" - expanded variant", name, out].join(" "));
807
+ for (const key2 in out) {
808
+ const value2 = out[key2];
809
+ isValidStyleKey(key2, staticConfig) ? acc.push({
810
+ type: "style",
811
+ value: {
812
+ [key2]: value2
813
+ },
814
+ name: key2,
815
+ attr: cur.value
816
+ }) : acc.push({
817
+ type: "attr",
818
+ value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 == "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
819
+ });
820
+ }
821
+ }
822
+ }
823
+ }
824
+ if (cur.type !== "style") return acc.push(cur), acc;
825
+ let key = Object.keys(cur.value)[0];
826
+ const value = cur.value[key],
827
+ fullKey = tamaguiConfig?.shorthands[key];
828
+ return fullKey && (cur.value = {
829
+ [fullKey]: value
830
+ }, key = fullKey), disableExtractVariables && value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey)) ? (shouldPrintDebug && logger.info([` keeping variable inline: ${key} =`, value].join(" ")), acc.push({
831
+ type: "attr",
832
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
833
+ }), acc) : (acc.push(cur), acc);
834
+ }, []), tm.mark("jsx-element-expanded", !!shouldPrintDebug), shouldPrintDebug && logger.info([` - attrs (expanded):
835
+ `, (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
836
+ let prev = null;
837
+ const getProps = (props, includeProps = !1, debugName = "") => {
838
+ if (!props) return shouldPrintDebug && logger.info([" getProps() no props"].join(" ")), {};
839
+ if (excludeProps?.size) for (const key in props) excludeProps.has(key) && (shouldPrintDebug && logger.info([" delete excluded", key].join(" ")), delete props[key]);
840
+ const before = process.env.IS_STATIC;
841
+ process.env.IS_STATIC = "is_static";
842
+ try {
843
+ const out = getSplitStyles(props, staticConfig, defaultTheme, "", componentState, {
844
+ ...styleProps,
845
+ noClass: !0,
846
+ fallbackProps: completeProps,
847
+ ...(options.experimentalFlattenThemesOnNative && platform2 === "native" && {
848
+ resolveValues: "except-theme"
849
+ })
850
+ }, void 0, void 0, void 0, void 0, !1, debugPropValue || shouldPrintDebug);
851
+ let outProps = {
852
+ ...(includeProps ? out.viewProps : {}),
853
+ ...out.style,
854
+ ...out.pseudos
855
+ };
856
+ for (const key in outProps) deoptProps.has(key) && (shouldFlatten = !1);
857
+ return shouldPrintDebug && (logger.info(`(${debugName})`), logger.info(`
858
+ getProps (props in): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props))}`), logger.info(`
859
+ getProps (outProps): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outProps))}`)), out.fontFamily && ((0, import_propsToFontFamilyCache.setPropsToFontFamily)(outProps, out.fontFamily), shouldPrintDebug && logger.info(`
860
+ \u{1F4AC} new font fam: ${out.fontFamily}`)), outProps;
861
+ } catch (err) {
862
+ return logger.info(["error", err.message, err.stack].join(" ")), {};
863
+ } finally {
864
+ process.env.IS_STATIC = before;
865
+ }
866
+ };
867
+ attrs.unshift({
868
+ type: "style",
869
+ value: defaultProps
870
+ }), attrs = attrs.reduce((acc, cur) => {
871
+ if (cur.type === "style") {
872
+ const key = Object.keys(cur.value)[0],
873
+ value = cur.value[key];
874
+ if (
875
+ // !isStyleAndAttr[key] &&
876
+ !shouldFlatten &&
877
+ // de-opt if non-style
878
+ !validStyles[key] && !pseudoDescriptors[key] && !(key.startsWith("data-") || key.startsWith("aria-"))) return shouldPrintDebug && logger.info([" - keeping as non-style", key].join(" ")), prev = cur, acc.push({
879
+ type: "attr",
880
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value == "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)))
881
+ }), acc.push(cur), acc;
882
+ if (prev?.type === "style") return mergeStyles(prev.value, cur.value), acc;
883
+ }
884
+ return cur.type === "style" && (prev = cur), acc.push(cur), acc;
885
+ }, []), shouldPrintDebug && logger.info([` - attrs (combined \u{1F500}):
886
+ `, (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
887
+ let getStyleError = null;
888
+ for (const attr of attrs) try {
889
+ switch (shouldPrintDebug && console.info(` Processing ${attr.type}:`), attr.type) {
890
+ case "ternary":
891
+ {
892
+ const a = getProps(attr.value.alternate, !1, "ternary.alternate"),
893
+ c = getProps(attr.value.consequent, !1, "ternary.consequent");
894
+ a && (attr.value.alternate = a), c && (attr.value.consequent = c), shouldPrintDebug && logger.info([" => tern ", (0, import_extractHelpers.attrStr)(attr)].join(" "));
895
+ continue;
896
+ }
897
+ case "style":
898
+ {
899
+ const styles = getProps(attr.value, !1, "style");
900
+ styles && (attr.value = styles), shouldPrintDebug && logger.info([" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value))].join(" ")), shouldPrintDebug && logger.info([" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles))].join(" "));
901
+ continue;
902
+ }
903
+ case "attr":
904
+ if (shouldFlatten && t.isJSXAttribute(attr.value)) {
905
+ const key = attr.value.name.name;
906
+ if (key === "style" || key === "className" || key === "tag") continue;
907
+ const value = attemptEvalSafe(attr.value.value || t.booleanLiteral(!0));
908
+ if (value !== import_constants.FAILED_EVAL) {
909
+ const outProps = getProps({
910
+ [key]: value
911
+ }, !0, `attr.${key}`),
912
+ outKey = Object.keys(outProps)[0];
913
+ if (outKey) {
914
+ const outVal = outProps[outKey];
915
+ attr.value = t.jsxAttribute(t.jsxIdentifier(outKey), t.jsxExpressionContainer(typeof outVal == "string" ? t.stringLiteral(outVal) : (0, import_literalToAst.literalToAst)(outVal)));
916
+ }
917
+ }
918
+ }
919
+ }
920
+ } catch (err) {
921
+ getStyleError = err;
922
+ }
923
+ if (shouldPrintDebug && logger.info([` - attrs (ternaries/combined):
924
+ `, (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" ")), tm.mark("jsx-element-styles", !!shouldPrintDebug), getStyleError) return logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" ")), node.attributes = ogAttributes, null;
925
+ const existingStyleKeys = /* @__PURE__ */new Set();
926
+ for (let i = attrs.length - 1; i >= 0; i--) {
927
+ const attr = attrs[i];
928
+ if (shouldFlatten && attr.type === "attr" && t.isJSXAttribute(attr.value) && t.isJSXIdentifier(attr.value.name)) {
929
+ const name = attr.value.name.name;
930
+ INLINE_EXTRACTABLE[name] && (attr.value.name.name = INLINE_EXTRACTABLE[name]);
931
+ }
932
+ if (attr.type === "style") for (const key in attr.value) existingStyleKeys.has(key) ? (shouldPrintDebug && logger.info([` >> delete existing ${key}`].join(" ")), delete attr.value[key]) : existingStyleKeys.add(key);
933
+ }
934
+ if (options.experimentalFlattenThemesOnNative && (attrs = attrs.filter(Boolean)), !shouldFlatten && inlineWhenUnflattened.size) {
935
+ for (const [index, attr] of attrs.entries()) if (attr.type === "style") for (const key in attr.value) {
936
+ if (!inlineWhenUnflattened.has(key)) continue;
937
+ const val = inlineWhenUnflattenedOGVals[key];
938
+ val ? (delete attr.value[key], attrs.splice(index - 1, 0, val.attr)) : delete attr.value[key];
939
+ }
940
+ }
941
+ if (attrs = attrs.filter(x => !(x.type === "style" && Object.keys(x.value).length === 0)), !shouldFlatten && platform2 === "native") return shouldPrintDebug && logger.info(`Disabled flattening except for simple cases on native for now: ${JSON.stringify({
942
+ flatNode: flatNodeName,
943
+ shouldDeopt,
944
+ canFlattenProps,
945
+ hasSpread,
946
+ "staticConfig.isStyledHOC": staticConfig.isStyledHOC,
947
+ "!staticConfig.isHOC": !staticConfig.isHOC,
948
+ "staticConfig.isReactNative": staticConfig.isReactNative,
949
+ "staticConfig.neverFlatten": staticConfig.neverFlatten
950
+ }, null, 2)}`), node.attributes = ogAttributes, null;
951
+ shouldPrintDebug && (logger.info([` - inlined props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" ")), logger.info(` - attrs (end):
952
+ ${(0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))}`)), onExtractTag({
953
+ parserProps: propsWithFileInfo,
954
+ attrs,
955
+ node,
956
+ lineNumbers,
957
+ filePath,
958
+ config: tamaguiConfig,
959
+ flatNodeName,
960
+ attemptEval,
961
+ jsxPath: traversePath,
962
+ originalNodeName,
963
+ programPath,
964
+ completeProps,
965
+ staticConfig
966
+ }), shouldFlatten && (shouldPrintDebug && logger.info([" [\u2705] flattened", originalNodeName, flatNodeName].join(" ")), node.name.name = flatNodeName, res.flattened++, closingElement && (closingElement.name.name = flatNodeName));
967
+ } catch (err) {
968
+ node.attributes = ogAttributes, err instanceof import_errors.BailOptimizationError || (console.error(`@tamagui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment TAMAGUI_DEBUG=1`), process.env.TAMAGUI_DEBUG === "1" && console.error(err.stack));
969
+ } finally {
970
+ debugPropValue && (shouldPrintDebug = ogDebug);
971
+ }
972
+ }
973
+ }), tm.mark("jsx-done", !!shouldPrintDebug), tm.done(shouldPrintDebug === "verbose"), res;
974
+ }
975
+ }
976
+ //# sourceMappingURL=createExtractor.mjs.map